Android the content of the adapter have changed but ListView do not receive a notification

Source: Internet
Author: User

 is  from  from the UI thread

Reason: There is no notification in the main thread ....

1, where the bug appears listview.class 1487 rows if (Mitemcount = = 0) {resetlist ();                Invokeonitemscrolllistener ();            Return } else if (Mitemcount! = Madapter.getcount () {                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, Only "                         + "from the UI thread. [In ListView ("+ getId () +", "+ getclass ()             & Nbsp;            + ") with Adapter (" + mAdapter.getCl() ()             }  2, MItemCount! = Madapter.getcount ()? Adapterview.class  172 line       @ViewDebug .exportedproperty    the int mitemcount;//should be the number that was last loaded, the private3, Adapterview.class? ListView extends Abslistviewabslistview extends adapterview<listadapter> 4, the main way to solve the network maffairlist.setvisibility ( View.gone); madapter.notifydatasetchanged (); maffairlist.setvisibility (view.visible);only when proactive notifications are resolved, in most cases without notification5. What is madapter.notifydatasetchanged () doing? Click to enter class Baseadapter public void Notifydatasetchanged () {mdatasetobservable.notifychanged (); } point in class Datasetobservable public void Notifychanged () {synchronized (mobservers) {for (datasetobserve R Observer:mobservers) {observer.onchanged (); }}} point in the abstract class Datasetobserverpublic voidonChanged (){//Do nothing}         Adapterview.class class Adapterdatasetobserver extends Datasetobserver {private parcelable minstancestate = null; @Override public voidonChanged (){//Implementation MethodMdatachanged = true;molditemcount = Mitemcount;Mitemcount = Getadapter (). GetCount ();//Key Place... ... 6, theoretical solution the list loaded by the ListView is static, the size will not change as long as the list size () changes, immediately send notification 7, my suggestion as long as the list size () changes, immediately notify the main list of size () Changes and notification updates will have a time difference, scrolling the ListView without changing the master list size will greatly reduce the bug, or minimize the animation

Android the content of the adapter have changed but ListView do not receive a notification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.