2012-02-23 55 views
1

我用三個tabs.when我單擊該選項卡,顯示多個列表視圖與header.For,我使用listadapter 活動開始,我的代碼似乎adapter.addsection ("Header String",new ArrayAdapter(this,R.layout.row,cursor,from,to);然後我用 list.setadapter設置列表(適配器) 。當我點擊標籤時,所有工作正常。我發生問題後,我滾動我的列表查看這是在另一個活動和 按模擬器返回按鈕,並單擊tab.Now當我點擊標籤,我的應用程序崩潰,logcat顯示以下錯誤。android中的java.lang.IllegalStateException?

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(-1, class android.widget.ListView) with Adapter(class com.t.s.SeperatedListAdapter)] 

這是什麼解決方案?我用adapter.notifydatasetchanged()來解決這個問題。但是我不能。

+0

檢查來自鏈路的下列答案[計算器] [1] [計算器] [2] [計算器] [3] [1]:http://stackoverflow.com/questions/3132021/ android-listview-illegalstateexception-the-adapter-the-adapter-has-changed [2]:http://stackoverflow.com/questions/6478649/listview-illegalstateexception-the-content-of-the-adapter -has-changed-but-list [3]:http://stackoverflow.com/questions/4290806/how-to-solve-this-issuethe-content-of-the-adapter-has-changed-but- listview-did – user1203673 2012-02-23 09:45:23

回答

0

的理由是: 您的數據發生變化時,當回以前的活動,列表視圖會自動刷新,此時系統中找到的數據更改,但沒有notifyDataChanged調用,所以扔的錯誤。

所以如果另一個活動更改數據,你可以嘗試:在你以前的活動方法:onResume,儘量使用notifyDataChanged通知。

+1

我用notifydatasetchanged無論我哪裏可以..ecret但它崩潰。 – Mercy 2012-02-23 10:17:13

+0

@mercy:我也面臨同樣的問題,你有沒有解決這個問題 – 2012-08-10 09:58:57

相關問題