在我的 AmazingListView中选择一个项目时,我收到以下错误。我正在通过 AsyncTask (inBackround()) 加载数据,并每加载 20 个项目调用 adapter.notifyDataSetChanged() 和 onPostExecute 方法。列表加载没有任何问题,当我在加载列表后选择一个项目时,我没有任何问题......我只在列表加载期间选择项目时收到此错误。AmzingListView here中打开了一个问题,但两种解决方案都没有帮助我。任何想法都会被应用。
错误:
java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131034170, class com.foound.widget.AmazingListView) with Adapter(class android.widget.HeaderViewListAdapter)]
代码:
private ArrayList<object> list;
private class AsyncTask extends AsyncTask<Void, object, Void>
{
@Override
protected void onPreExecute()
{
list = populatList();
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... urls)
{
Log.i("CallLogActivity", "CallLog is Loading");
for (int i = 0; i < list.size(); i++)
{
String str = getString();
boolean bool = getBoolean();
Object c = new Object(str,bool);
publishProgress(c);
}
//Doing Work Here!!
return null;
}
@Override
protected void onPostExecute(Void result)
{
adapter.notifyDataSetChanged();
}
@Override
protected void onProgressUpdate(object... object)
{
count++
updatelist(object);
if (adapter != null)
{
if (count > 20)
{
adapter.notifyDataSetChanged();
count = 0;
}
}
super.onProgressUpdate(object);
}
}