Filter listview will not be updated until the keyboard is hidden or the back button is pressed

I have a listview that displays a list of contacts. I added an EditText to the layout above the list so I can search with a filter. I implemented this using the onTextChanged listener in EditText. My listview adapter is a custom adapter that extends BaseAdapter and implements Filterable. My filter works and does the job correctly. The problem is that when I type, the data set is updated, but the list itself is not updated until I hide the keyboard or press the return key. If I try to click on the list after entering some text in EditText, but before I close the keyboard or press the return key, I get this error:

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. 

Now, I definitely do not change the contents of the adapter from a thread other than a user interface thread.

Can someone explain what might cause this problem?

Actually, I found a workaround by calling Activity.onContentChanged() , but I'm still wondering why I really need to update manually.

+3
android filter listview
source share
3 answers

I finally found a way to do this. The thing is, the dataset was refreshing when I called notifyDataSetChanged(); , but the views did not redraw, I have no idea why (maybe something is wrong with me using the ViewHolder template, maybe? Just a random guess ...). So what I did was call getListView().invalidateViews(); , and views will be redrawn with the correct data.

+5
source share

you can use setNotifyOnChange (), which automatically calls notifyDataSetChanged (). it actually notifies attached observers that the baseline data has been changed, and any view reflecting the data set must be updated.

0
source share

I had some kind of problem and I tried many solutions without a good result.

I solved this release by adding android:hardwareAccelerated="true" to the manifest file for my activity.

Try using this solution, it can help you.

0
source share

All Articles