dispatching input event

暑假在做Android的課程設計,大致上做完了,可是在用的時候,偶爾的就會“很抱歉,您的程序已停止運行”,那個部分大致是這樣的:單擊ListVIew clalist列表的一項,可跳轉到詳情界面,然後就在我退回listview界面再點擊任意item的時候,問題就時不時地來了,由於不是每回都停止運行,我一直都不知道問題出在哪,查看log日誌就是這麼句話“dispatching input event”,“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.”意思是數據源變了,確實是,在退回listview 界面的時候,我刷新了一下界面,把填充數據list清空再加載,(我是在onResume()方法中寫的這些)
protected void onResume() {
	    mylist.clear();
		BmobQuery<Acti> actis=new BmobQuery<Acti>();
		actis.addWhereEqualTo("classId", classid);
		actis.addWhereEqualTo("isexit", 1);
		actis.findObjects(ShowclassActivity.this, new FindListener<Acti>() {
			
			@Override
			public void onSuccess(List<Acti> arg0) {
				actilist=arg0;
				for(int i=0;i<arg0.size();i++){
					Acti act=arg0.get(i);
					HashMap map=new HashMap();				
					map.put("name", act.getName());
					map.put("num",i+1);
					mylist.add(map);					
				}
				adapter=new SimpleAdapter(ShowclassActivity.this, mylist,
						R.layout.actilist, new String[]{"name","num"}, new int[]{R.id.actname,R.id.actnum});				
				clalist.setAdapter(adapter);
				adapter.notifyDataSetChanged();
			}

list被清空後有一些耗時的操作,calist才重新綁定新的list,如果在這之前我點擊item,list改變了但是在界面上,依舊顯示原來的list,所以會報錯啦,怎麼改呢?So easy啦,修改mylist之後,在耗時操作之前,不要讓原來的數據顯示在listview上面了,只需要在
 mylist.clear();

後面加一行代碼:

 clalist.setAdapter(null);

完美!

本來,一直找不着錯誤的我,打算抱着僥倖的心理,提交課設的敲打,一直祈禱着演示的時候不要有這種錯誤,現在,大笑

發佈了30 篇原創文章 · 獲贊 19 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章