Search code examples
javaandroidandroid-fragmentsandroid-listfragment

Updating ListView fragment when not focused


I'm working on a tablet application with a ListView fragment on the left, and some other views including a SearchView (essentially a TextView) on the right. When the SearchView is focused, I want to update the data of the listview, but I can't. If I notifyDataSetChanged on the UI thread, nothing happens. If I call setAdapter() again on my listview, the listview goes blank.

Only when I touch the listview again (it gets temporary focus again or something to cause getView() to be called on the adapter) does it get updated.

Anyone got an idea on how to fix this?

Min-Sdk and Target is 4.0.3.


Solution

  • What now works for me is updating the data in the underlying adapter and then calling notifyDataSetChanged on that adapter, all from the UI thread.

    I did not need to call setAdapter again on the listView.

    Of course I had already tried all this before asking the question, so not sure what made it suddenly start working.