zoukankan      html  css  js  c++  java
  • Android开发-- The content of the adapter has changed but ListView did not receive a notification

    最近在联系开发DaysMatter时遇到一个问题:

    app中使用ListView来展示所有事件,每次添加完事件后使用下面代码来更新ListView.

    1 toDoListView.refreshDrawableState();

    会出现如下错误,错误内容是讲ListView的adapter必须是在UI线程中修改,不能在后台线程中修改

    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(2131034172, class android.widget.ListView) 
    with Adapter(class android.widget.SimpleAdapter)]

    在SO上看到一个类似的问题(http://stackoverflow.com/questions/9771017/the-content-of-the-adapter-has-changed-but-listview-did-not-receive-a-notificati), 解决方法:

    1 runOnUiThread(new Runnable() {
    2   public void run() {
    3     mAllResultsItem.add(item);
    4     mAllResultsAdapter.notifyDataSetChanged();
    5   }
    6 });
  • 相关阅读:
    从零开始写自己的PHP框架系列教程[前言]
    从零开始写自己的PHP框架系列教程(二)[App.php]
    Nginx
    常见的CSS
    常用JS代码
    jq常用
    EMMET 的HTM自动生成
    JS的小判断
    ARM寄存器与ATPCS/AAPCS
    关于笔记本电脑随想
  • 原文地址:https://www.cnblogs.com/feiling/p/3998481.html
Copyright © 2011-2022 走看看