我不确定为什么会这样,但我无法在非静态的异步任务中调用方法。
protected void onPostExecute(String result) {
List<SingleEvent> thelist = PhotosActivity.parseJSONResponse(result);
PhotosActivity.refreshListView(thelist);
}
我 Activity 中的方法:
public void refreshListView(List<SingleEvent> theList){//method that adds the List to the ListView after asyncTask is finished.
SingleEventAdapter adapter = new SingleEventAdapter(this, theList);
this.list.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
它说我应该将我的方法设为静态,但在这样做时内部代码会出错,说它不能与静态一起使用。
编辑:
以下是我的异步任务类:
public class CallWebServiceTask extends AsyncTask<String, Object, String> {}
它不是静态的吗?
最佳答案
您必须这样做(确保您的 AsyncTask
类不是静态的):
PhotosActivity.this.refreshListView(thelist);
关于android - 从我的 asynctask 调用的方法必须是静态的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7930852/