Domanda

I have a listview that displays a list of profiles added by a user. If no profiles exist, I set the listview visibility to "gone".

I have a context menu on the listview that allows a user to delete a profile. When doing this, I display a dialog window to confirm they want to delete the profile.

If the user selects "Yes" on the dialog by touching the button, everything works fine.

If the user selects "Yes" using the trackball, then touches the screen, the app crashes.

I can prevent the crash by commenting out the line of code that sets the listview visibility to "gone". I'm curious what's causing the crash (want to understand).

The error seems misleading to me, which is: 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

È stato utile?

Soluzione

The adapter that the ListView was using just needed to be notified that the data changed (notifyDataSetChanged()). Still not sure why the behavior is different between using the trackball vs touch, but I have a better understanding of how the adapter works now.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top