I will explain my actual problem.
If needed I will also attach some code.
The scenario is this: I've created an EndlessList attaching the list to a OnScrollListener. When I'm reaching the end of the List I start an AsyncTask (if there is data to load).
In the preExecute I add to the footer a view (spinner). In the doInBackground I fetch data from internet and in the onPostExecute I add data to the adapter and I remove the footer View (the loading spinner). You have to remove it because you cannot access to that view and put it on GONE.
In my code I never do a notifyDataSetChange because in the adapter(ArrayAdapter that I've cloned from JB source code), when you do an addAll it automatically do it
/**
* 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();
}
It works well but sometimes it crash with this damn error and I've no clue to solve it:
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)