1

I am fetching contacts and this work is going fine. But I am try to also show the contacts in bunch of 50 which is fetched, i.e. user don't have to wait until all contacts has been fetched. I try to with Asynctask , And Thread also but when I go to notify the list adapter then error has came.

"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. Make sure your adapter calls notifyDataSetChanged() when its content changes"

Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49
  • where are you fetching your contacts from? how many contacts do you have in total? – pskink May 03 '18 at 06:24
  • From Android Database. I have 8000 Contacts But i resolved the prob Actually you have to add collection (list) add in UI thread if you notify the list in UI thread this is very awkward for me earlier. https://stackoverflow.com/questions/3132021/android-listview-illegalstateexception-the-content-of-the-adapter-has-changed – Bhanu Sharma May 03 '18 at 07:50
  • 1
    simply use google's [paging](https://developer.android.com/topic/libraries/architecture/paging.html) support library - no need for reinventing the wheel – pskink May 03 '18 at 07:52

1 Answers1

0

Make sure you update the adapter from the onProgressUpdate() method of the AsyncTask. The onProgressUpdate() can be invoked by calling the publishProgress() from inside yourdoInBackground(). doInBackground() runs in the Background Thread, while onProgressUpdate() runs in your UI thread.

Sriram
  • 359
  • 1
  • 13