-1

Full exception : Unhandeled exception: 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. [in ListView(2131296364, class android.widget.ListView) with Adapter(class elfar.insitemobile.Tabs.EventTable$EventTableListAdapter)]

It happens only when the app starts (the list is updating with the pending events), and it happens only sometimes. I noticed that it happened when there are a lot of pending events to update in the list when the app starts. If there are only few items to update it wont happen.

I tried to run those list changes inside of a thread and placed notifyDataSetChanged() after each update, but it still happens.

Taher A. Ghaleb
  • 5,120
  • 5
  • 31
  • 44
Ohados
  • 83
  • 3
  • 13

2 Answers2

1

Well this might seem obvious but it happens very often - make sure you aren't adding items to your ArrayList (or any other list that you are using) outside the UI thread. So be sure to add the items and call notifyDataSetChanged() in the UI thread. This SO post might be of further assistance: Android, ListView IllegalStateException: "The content of the adapter has changed but ListView did not receive a notification"

Hopefully this helps!

AvidRP
  • 373
  • 2
  • 11
  • Yea, but how can i call it inside of the UI thread? right now im calling the Remove and Add functions using a Handler (new Handler(Looper.getMainLooper()) and its post method – Ohados Dec 04 '18 at 11:46
0

UPDATE: i solved the following issue by inserting the calls of the Add and Remove functions into a new Runnable of a handler that was created with the mainLooper.

private static Handler mHandler = new Handler(Looper.getMainLooper());

mHandler.post(new Runnable() {

        @Override
        public void run() {
            lMessages.add(0,message);
            ...
}
Ohados
  • 83
  • 3
  • 13