【问题标题】:content of the adapter has changed but ListView did not receive a notification适配器的内容发生了变化,但 ListView 没有收到通知
【发布时间】:2014-06-21 09:58:56
【问题描述】:

我收到以下错误:

Java.lang.IllegalStateException:适配器的内容已更改,但 ListView 没有收到通知。确保适配器的内容不是从后台线程修改的,而只是从 UI 线程修改的。

我从onPostExecute 方法调用,我在设置适配器之后,我正在做setNotifyDataChanged 但仍然无法正常工作。为什么?

if(forumqbfilter_list.size() > 0 && forumqbfilter_list != null) { 
    forumAdapter = new ForumAdapter(ForumViewActivity.this); 
    LV_forums.setAdapter(forumAdapter); forumAdapter.notifyDataSetChanged(); 
} else { 
    Toast.makeText(getApplicationContext(), "No Forums Available", 20).show(); 
} 

【问题讨论】:

  • 您应该在从主UiThread 更新适配器数据后调用adapter.notifyDataSetChanged();
  • 我已经在打电话了,但还是打不通
  • 为什么?发布我想看的代码。你怎么打电话的?
  • 这是什么?编辑您的问题并在您的问题中发布您的所有代码。
  • if(forumqbfilter_list.size() > 0 && forumqbfilter_list != null) { forumAdapter = new ForumAdapter(ForumViewActivity.this); LV_forums.setAdapter(forumAdapter); forumAdapter.notifyDataSetChanged(); } else { Toast.makeText(getApplicationContext(), "没有可用的论坛", 20).show(); }

标签: android android-listview android-adapter illegalstateexception


【解决方案1】:

致电adapter.notifydatasetchanged() 更新您的列表视图。

【讨论】:

  • forumAdapter.notifyDataSetChanged();我正在添加但仍然无法正常工作
猜你喜欢
  • 1970-01-01
  • 2015-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多