解决The content of the adapter has changed but ListView did not receive a notification

问题分析:

log的信息很简单,就是在改动ListView内容后,没有调用notifyDataSetChanged函数来更新,才导致的异常。

04-21 14:53:58.074: E/AndroidRuntime(29258): 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. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(16908298, class com.handmark.pulltorefresh.library.PullToRefreshListView$b) with Adapter(class android.widget.HeaderViewListAdapter)]
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.widget.ListView.layoutChildren(ListView.java:1555)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4372)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.view.Choreographer.doFrame(Choreographer.java:543)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.os.Handler.handleCallback(Handler.java:733)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.os.Handler.dispatchMessage(Handler.java:95)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.os.Looper.loop(Looper.java:136)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at android.app.ActivityThread.main(ActivityThread.java:5096)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at java.lang.reflect.Method.invokeNative(Native Method)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at java.lang.reflect.Method.invoke(Method.java:515)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-21 14:53:58.074: E/AndroidRuntime(29258):    at dalvik.system.NativeStart.main(Native Method)

解决方法:

1.首先保证不在线程中调用notifyDataSetChanged函数。
2.在每次涉及到修改ListView内容时,一定要调用notifyDataSetChanged即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值