First off, I have looked around the site and could not find a solution to my question, other than “hide the ListView”. This is not a viable solution in my case!
So, the problem:
I have created my own “EndlessAdapter” which allows me to populate the ArrayList<> backing the ListView with more data as the user scrolls to the bottom of the List. This all works perfectly, except for when the user selects a Row whilst the List is updating, or changes orientation whilst the List is updating (I suppose it could be any UI interactions).
I have wrapped my mAdapter.notifyDatasetChanged() method in a try catch, but I can never seem to catch this IllegalStateException, so I do not know where is it occurring!
Is there a way, whilst the Adapter is updating the ListView, that I can block the user from interacting with the application until its finished? The long part of the EndlessAdapter process is the downloading of the new data. Updating the ListView is a fast process imo.
I really need to get this issue sorted. Id rather not post up source code, but if need be I can try and post up the vitals? Otherwise I would be very appreciative if someone with experience in this could have a chat over Email or IM?
Here is the stack trace:
04-05 21:11:35.363: ERROR/AndroidRuntime(25707): 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 com.mimminito.heatdroid.view.DealsView$DealAdapter)
Here is a link to a sample of my code:
http://pastebin.com/wfmWSGwQ
I create the Adapter in the onCreate(). I then assign the Adapter to the ListView once the XML has been parsed. In the same method I call the updateList() method. This gets the data that has been downloaded, and then notifies the mAdapter that its data has been changed (all run on the UI thread)
Thanks for your time
Adam
You’re doing both the adding to the list and the notify in the UI-thread as it says? This is the only way to guarantee that the list is not used by the UI and your other threads at the same time.