前言
在做項目的過程中,遇到了一個問題:
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.
原因
在執行listview刷新操作時,當listview的adapter中的數據更新了,但是listview還未來得及刷新,這時,你點擊了該listview,便會拋出這個異常。
解決方案
設置listview的visibility
listview.setVisibility(View.VISIBLE/View.GONE)
操作
在執行更新listview數據的操作前設置
listView.setVisibility(View.GONE);
在數據更新操作完成后設置
listView.setVisibility(View.VISIBLE);