我有一个 ArrayAdapter
,其中包含一个 AsyncTask
,但我不确定如何从 onPostExecute
调用 notifyDataSetChanged
示例:
public class ColorAdapter extends ArrayAdapter<Color> {
List<Color> colorList;
Context context;
....
public ColorAdapter(Context context, List<Color> list) {
this.context = context; this.colorList = list;
}
public View getView (final int position, final View view, final ViewGroup parent) {
.....
}
class DeleteColorTask extends AsyncTask <String, String, String> {
int colorId;
DeleteColorTask (int colorId) {this.colorId = colorId;}
protected String doInBackgroud (String ... args) {
//call to server to delete the color
colorList.remove(colorList.indexOf(...));
}
protected void onPostExecute(String s) {
//HOW CAN I CALL notifyDataSetChanged() here?? this.notifyDataSetChanged() doesn't work since I am inside DeleteColorTask class
}
}
}
我这样从我的活动中调用上述内容:
adapter = new ColorAdapter(context, colorsList);
setListAdapter(adapter);
notifyDataSetChanged
,并使onPostExecute
调用该void。 - Rotary Heart