When using adapter in Android programming, the following error occurs occasionally: the content of the adapter has changed but the ListView does 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 log in the DDMS is also unable to locate the exact error location. Check the error can start from the following points: 1, check the thread, determine that there is no direct call adapter in the background thread, if there is, remove the relevant code to handler processing; 2, try to put the data in the adapter class to manage, Do not need to clear the information (write clear ()), timely use notifydatasetchanged () refresh, 3, in the activity or fragment suitable position (onpause/onstop) to check thread in time, have adapter data processing related should stop immediately; 4. This error often occurs after the activity is dormant, mainly using the adapter is not carefully caused. If the reason is not found, stop all background thread in the OnPause () function and empty the data in adapter at the front of the Onresume () function, and adapter.notifydatasetchanged (). Then re-update the load data, which generally resolves the issue. -----------------------------------------
Many novices may not be very clear about the thread and message as well as the handler, Looper concepts in Android development, and may produce something like the content of the adapter have changed but a ListView did no T receive a notification make sure the content of your adapter are not modified from a background thread. But only the error from the UI thread. Here are a few points to help you understand the problem:
1. Change the adapter adapter content when not in the background thread, must be processed in the UI thread, this can be resolved by handler outgoing.
2. Try adapter's notifydatasetchanged () method, of course, mainly look at your code details.
The above only seems to be the wrong message translated only, the real reason please see the source code:
Mitemcount = Madapter = = null? 0:madapter.getcount ();
...//In the middle is the other code is not copied
else if (mitemcount! = Madapter.getcount ()) {//Here can be seen why the adapter has changed, is because you may also be wired to run, updated madapter.getcount (); The return value
throw new IllegalStateException ("The content of the adapter have changed but"
+ "ListView did not receive a notification. Make sure the content of "
+ "Your adapter is not modified from a background thread, and only"
+ "from the UI thread. [In ListView ("+ getId () +", "+ getclass ()
+ ") with Adapter (" + madapter.getclass () + ")]");
============
PS: Know it, know the reason why. At first I found that writing notifydatasetchanged () can achieve the effect, so I put it annotated, until the problem, I read the above content, I understand why there will be adapter has changed hints, Also understand the meaning of notifydatasetchanged ().
My understanding is that the increase in content length has changed, but no notification has been made to update the content added in the selection, causing the array to go out of bounds (or other problems)
So remember to update after adding content.
Android Adapter Error The content of the adapter have changed but the ListView does not receive a notification.