在我的AmazingListView中选择项目时出现以下错误。我通过AsyncTask(inBackround())加载数据,每调用20个项目并调用adapter.notifyDataSetChanged()方法onPostExecute。该列表加载时没有任何问题,当我在加载列表后选择一个项目时,我没有任何问题......我只在列表加载期间选择项目时出现此错误。在AmzingListView here中打开了一个问题,但这两个解决方案都没有帮助我。任何想法都会被处理。使用AsyncTask加载AmazingListView时出错
错误:
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);
}
}
你是否在你的“做工”代码中更改适配器的内容? (因为我注意到你的postExecute是'Void') – Tom
是的我在“做功”期间改变了适配器的内容,我发现它一直在更新。问题是当我在列表中选择项目时。 – user1163234
您是否检查过错误消息是否始终没有说出真相 - 作为第一步,将代码中将适配器更改为runOnUIThread(Runnable ...)的部分。 (http://developer.android.com/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable)) – Tom