2013.05.16——— android 关于listview的bug
16lz
2021-12-04
2013.05.16——— android 关于listview的bug
参考:http://www.pocketdigi.com/20111018/548.html
错误信息
自认为代码没有写错 但是 如果 我切换activity速度非常快的话 基本上都会报这个错
我的代码如下:
然后 我在handler里面 更新listview
这个就是我老是报错的代码 我在线程里面 更改了adapter绑定的数据,然后再handler里面 更新listview
搜了下,发现很多人都遇到这个问题
说这样写可以解决 反正我这样写是没解决 可能我写的有问题吧
最后,我把ListView的添加,删除,清空等UI操作都用Handler来处理,上面的代码 稍微改下
新写一个临时的list集合 用于存储得到的数据
就这样 我大概测了下 暂时没再遇到这个问题
参考:http://www.pocketdigi.com/20111018/548.html
错误信息
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(2131165479, class com.wmyc.activity.com.listview.pulllistview.XListView) with Adapter(class com.wmyc.activity.com.listview.multicolumnlistview.internal.PLA_HeaderViewListAdapter)] mItemCount: 2, mAdapter.getCount(): 7
自认为代码没有写错 但是 如果 我切换activity速度非常快的话 基本上都会报这个错
我的代码如下:
private class LoadDataThread implements Runnable{private int type;public LoadDataThread(int type){this.type = type;}@Overridepublic void run() {if(type==IXListViewListener.TYPE_REFRESH){mIndexShow = 0;}ArrayList<InfoCloth> list = mDaoCloth.getAllByPage(mIndexShow, mTagId);//分页加载数据switch(type){case IXListViewListener.TYPE_LOADMORE:mArrData.addAll(list);break;case IXListViewListener.TYPE_REFRESH:mArrData.clear();mArrData.addAll(list);break;}System.out.println("LoadDataThread");if(mArrData.size()==DBOpenHelper.PAGE_COUNT){//如果达到每页显示个数 就分页mIndexShow = mIndexShow+1;}System.out.println("1111111111");if(list.size() < DBOpenHelper.PAGE_COUNT){System.out.println("2222222222");mHandler.sendEmptyMessage(MSG_FOOTVIEWGONE);}System.out.println("33333333333"); Message msg = new Message();msg.arg1 = type;msg.what = Constant.MSG_SUC; mHandler.sendMessage(msg); System.out.println("444444444444");}}
然后 我在handler里面 更新listview
//handlerprivate Handler mHandler = new Handler(){@Overridepublic void handleMessage(Message msg) {super.handleMessage(msg);if(_dialog!=null && _dialog.isShowing()){_dialog.dismiss();}switch(msg.what){case Constant.MSG_FAIL:break;case Constant.MSG_SUC:showData();break;}}};
这个就是我老是报错的代码 我在线程里面 更改了adapter绑定的数据,然后再handler里面 更新listview
搜了下,发现很多人都遇到这个问题
listView1.setVisibility(View.GONE);listAdapter.notifyDataSetChanged();listView1.setVisibility(View.VISIBLE);
说这样写可以解决 反正我这样写是没解决 可能我写的有问题吧
最后,我把ListView的添加,删除,清空等UI操作都用Handler来处理,上面的代码 稍微改下
private class LoadDataThread implements Runnable{private int type;public LoadDataThread(int type){this.type = type;}@Overridepublic void run() {if(type==IXListViewListener.TYPE_REFRESH){mIndexShow = 0;}mArrDataTemp = mDaoCloth.getAllByPage(mIndexShow, mTagId);//分页加载数据 Message msg = new Message();msg.arg1 = type;msg.what = Constant.MSG_SUC; mHandler.sendMessage(msg); System.out.println("444444444444");}}
新写一个临时的list集合 用于存储得到的数据
case Constant.MSG_SUC:switch( msg.arg1){case IXListViewListener.TYPE_LOADMORE:mArrData.addAll(mArrDataTemp);break;case IXListViewListener.TYPE_REFRESH:mArrData.clear();mArrData.addAll(mArrDataTemp);break;}System.out.println("LoadDataThread");if(mArrData.size()==DBOpenHelper.PAGE_COUNT){//如果达到每页显示个数 就分页mIndexShow = mIndexShow+1;}System.out.println("1111111111");if(mArrDataTemp.size() < DBOpenHelper.PAGE_COUNT){System.out.println("2222222222");mFallView.setPullLoadEnable(false);}showData();break;}
就这样 我大概测了下 暂时没再遇到这个问题
更多相关文章
- android 数据库 备份还原
- Android(安卓)Studio Exception: Could not find method android
- Android(安卓)ListView强制停止滚动
- 2011.09.22——— android ViewStub的简单使用
- Android应用程序组件Content Provider的启动过程源代码分析(6)
- android常用代码片段
- Android(安卓)SQLiteOpenHelper(手机数据库)
- Android系统进程Zygote启动过程的源代码分析(3)
- Android(安卓)ListView SimpleAdapter ArrayList 数据更新问题 z