Java.lang.IllegalStateException:The content of the adapter have changed but ListView do not receive a notification. Make sure the content of your adapter are not modified from a background thread, but only from the UI thread. ...
The ListView encounters frequent updates to the data source and displays the Times wrong
Adapter inside the data Update (content) can not be in the background, or will be probabilistic error, error generally because the update data source and notifydatasetchanged is not on a thread
some workarounds:
threads are managed, and if the current actitivty is paused, these threads are stopped in a timely manner.
after the data is updated, use the Notifydatasetchanged () method to notify the UI in a timely manner to avoid inconsistent data.
update the data, preferably on the main thread. This allows you to use synchronous data to update the code for the part of the notification content update.
when multithreading is used, data can be cached, such as the data that is bound to the ListView is stored in ArrayList (DataList), and the data is first added to the temporary ArrayList (tmplist) in the thread. Finally, before calling the Notifydatasetchanged () method to notify the UI update, update the data in the temporary ArrayList (tmplist) to ArrayList (DataList). The temporary ArrayList (tmplist) data is then emptied.
/* Relative to the original, I made two changes: 1. All data is "fully" stored inside the adapter, and even if there is external data entry, it is used. Clone () to regenerate the copy, ensuring that the data is fully maintained by adapter. 2. Ensure that all setdevicelist ()/cleardevicelist () are called from the main thread, how to ensure that it is called from the main thread: A. Call the Activity.runonuithread () method; B. Use handler (this is not very accurate, because handler can also run on non-UI threads); c. Use Asynctask. */private class Deviceadapter extends Baseadapter {private Layoutinflater inflater; private arraylist<device> devices; Public Deviceadapter () {inflater = Layoutinflater.from (Mcontext); } @SuppressWarnings ("Unchecked") public void Setdevicelist (arraylist<device> list) {if (list! = null) {devices = (arraylist<device>) list.clone (); Notifydatasetchanged (); }} public void Cleardevicelist () {if (Devices! = null) {devices.clear (); } notifydatasetchanged (); } @Override public int getcount () {return devices = = null? 0:devices.size (); }//The following slightly ...
Java.lang.IllegalStateException