Android monkey causes adapter notification exception in android.widget.HeaderViewListAdapter file

I have a common problem:

java.lang.IllegalStateException: The content of the adapter has changed but List
View did not receive a notification. Make sure the content of your adapter is no
t modified from a background thread, but only from the UI thread. [in ListView(2
131427573, class android.widget.ListView) with Adapter(class android.widget.Head
erViewListAdapter)]

But the adapter is not my code, but in android.widget.HeaderViewListAdapter It uses Jellybean.

I read the source code HeaderViewListAdapter, ListAdapterand ListView. IllegalStateExceptioncalled when the number of items in is ListViewnot equal to the number provided ListAdapter. In this case, ListAdapteris HeaderViewListAdapter. The counter HeaderViewListAdapteris the source counter ListAdaptertransmitted by the client code, plus the size of the header and footer.

I have drawn my code. All access to ListViewis in the user interface thread, and it always follows notifyDataSetChanged(). I use one footer.

This does not occur under normal use. Is it because of the monkey? But how can Monkey change my variables from other threads?

  • Update after testing Monkey

I deleted the footer by deleting the call addFooterView(). The exception is the monkey. Should I delete the call in addFooterView()at some point?

+5
source share
3 answers

You can try adding something like this to your ListView:

    @Override
protected void layoutChildren() {
    try {
        super.layoutChildren();
    } catch (IllegalStateException e) {
        ZLog.e(LOG, "This is not realy dangerous problem");
    }
}

If you add a headerview or footViewiew ListView element, and when you notify the DataSetChanged () file, it will change the mItemCount value to the number of elements of the real adapter, but the right side will return a fake element that will add the headStount and footercount levels.

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/widget/ListView.java?av=f#1538

+9

. .

: EndlessList, OnScrollListener. , AsyncTask ( ).

preExecute (). doInBackground onPostExecute , View (). , GONE.

notifyDataSetChange, (ArrayAdapter, JB), addAll,

/**
 * Adds the specified Collection at the end of the array.
 *
 * @param collection The Collection to add at the end of the array.
 */
public void addAll(Collection<? extends T> collection) {
    synchronized (mLock) {
        if (mOriginalValues != null) {
            mOriginalValues.addAll(collection);
        } else {
            mObjects.addAll(collection);
        }
    }
    if (mNotifyOnChange) notifyDataSetChanged();
}

, , , :

 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(16908298, class android.widget.ListView) with Adapter(class android.widget.HeaderViewListAdapter)]
    at android.widget.ListView.layoutChildren(ListView.java:1545)
    at android.widget.AbsListView.onTouchModeChanged(AbsListView.java:2239)
    at android.view.ViewTreeObserver.dispatchOnTouchModeChanged(ViewTreeObserver.java:591)
    at android.view.ViewRoot.ensureTouchModeLocally(ViewRoot.java:2122)
    at android.view.ViewRoot.ensureTouchMode(ViewRoot.java:2106)
    at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2216)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1886)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    at dalvik.system.NativeStart.main(Native Method)
+1

.... ... android-amazing-listview. ,

(class android.widget.HeaderViewListAdapter)]).

, , →

, , getAdapter AmazingAdapter HeaderListViewAdapter, . getAdapter AmazingListView .

+1

All Articles