【发布时间】:2014-02-21 22:38:43
【问题描述】:
我有一个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。
标签: java android android-asynctask android-adapter