我有一个扩展listactivity的活动,在这个类中扩展我有一个扩展baseadapter的类。
现在在我的列表活动中我有这个 onCreate
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new BuildingAdapter(this));
final ProgressDialog loading = new ProgressDialog(this);
loading.setProgressStyle(ProgressDialog.STYLE_SPINNER);
loading.setTitle("Laddar");
loading.setMessage("Hämtar data från servern");
loading.show();
new AsyncTask<Void, Void, DataPacket.Data>()
{
@Override
protected DataPacket.Data doInBackground(Void... params){
return ServerConnection.getBuildings();
}
@Override
protected void onPostExecute(DataPacket.Data param) {
((MainenanceApplication)getApplication()).setDataStructure(param);
loading.dismiss();
//((BuildingAdapter)getListAdapter()).notifyDataSetChanged();
setListAdapter(new BuildingAdapter(BuildingSelectionActivity.this));
}
}.execute();
}
这按预期工作,但我的问题是在 onPostExecute 我更新列表适配器使用的数据结构。为什么我不能只调用 notifyDataSetChanged ?
如果我有该行,则视图不会自行更新,但是如果我使用 setListAdapter 下的行,则一切正常。