2

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.

my list-view contains huge data`s

am calling the bellow code using handler when the data is changed in the list

  listviewAdapter.notifyDataSetChanged();

but i get the same error some times and not every time i load it thanks in advance

Sathyapradeep
  • 163
  • 1
  • 10

3 Answers3

2

the question is not where the adapter update, it should be: the time the adapter update.

it look likes: your data bind to the adapter has be changed, and the ui have be updated, so this time, the system find the data changed but can't invoke the notifyDataSetChanged.

so, suggestion when you change the adapter's data, invoke notifyDataSetChanged immediately,

or

dont directed change the adapter's data in your thread, you should send the data to the hanlder, and in the handler using the data to replace or change the adapter's data and notifyDataSetChanged.

so anyway, suggestion get the data can run in background thread, and update the data , notifyDataSetChanged used in ui thread.

idiottiger
  • 5,147
  • 2
  • 25
  • 21
  • am not changing the adapters data from background thread.. also i am calling notifyDataSetChanged when ever the content of the list which is given to the adapter is changed.. i get this error only when huge datas like more than 500+ datas getting loaded into the list – Sathyapradeep Apr 20 '12 at 07:29
  • so, can you describe how do you update the adapter's data shortly? – idiottiger Apr 20 '12 at 07:36
  • i change the list in the background thread which in turn given to the adapter initially.. after changing i call the handler(UI Thread) in handler i cal notifyDataSetChanged().. this is the one exactly i do but i get this exception while huge data`s are there but i dint get this error with small(upto 300 list items) amount of data`s i call this notifyDataSetCahnged for refreshing my list with new or updated data`s – Sathyapradeep Apr 20 '12 at 07:43
  • `i change the list in the background thread which in turn given to the adapter initially`, if you just update the list's data ,it maybe ok, but if change the list's size, like add some item, in some rare time, it has some problem, so when you want to change the list's size, can you send the new data to the `hanlder`, and update in `handler` ? – idiottiger Apr 20 '12 at 07:50
  • no am not adding items to the list but i change the data`s with some modifications – Sathyapradeep Apr 20 '12 at 08:10
0

the error is quite clear. You have not to call listviewAdapter.notifyDataSetChanged(); from a thread different of the UI thread.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • Adding to it, you can call `listviewAdapter.notifyDataSetChanged();` from a Non UI Thread using `runOnUiThread()` – Lalit Poptani Apr 20 '12 at 07:15
  • 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,**bold** `but only from the UI thread` – Sathyapradeep Apr 20 '12 at 07:23
  • we should change only from UI thread.. am changing from UI thread only – Sathyapradeep Apr 20 '12 at 07:26
0

Modify the arguments of the adapter in runOnUIThread() or use a handler to notify the adapter that the dataset has changed.

user936414
  • 7,574
  • 3
  • 30
  • 29