Android ICS ListView Update Issue

I have a ListView on my Android application in which I am dynamically changing data. I use the onFilterComplete() method to modify the contents of a ListView.

Pre Ice Cream Sandwhich, which works in the following code:

 if(adapter != null) { adapter.notifyDataSetInvalidated(); lview3.invalidateViews(); adapter.getFilter().filter(aa1.getItem(item), new Filter.FilterListener() { public void onFilterComplete(int count) { adapter.notifyDataSetChanged(); if(lview3.getCount() == 0){ lview3.setVisibility(View.GONE); } else{ lview3.setVisibility(View.VISIBLE); } }}); 

However, on Ice Cream Sandwhich, when I use a filter, the screen does not refresh properly. If the filter returns several records that are smaller than the previous ListView, then the old list data is still visible in the background, according to this screenshot:

enter image description here

In the screenshot you can see where the first entry is in the ListView, that’s all that should be visible, you can see where the previous results are still visible from below, they are just visible, that they don’t function, they cannot be involved in them, as if the screen did not refresh properly.

When I select the home button to leave the application using the main screen, and return everything as it should, as shown in the following screenshot:

enter image description here

Is there anything else I have to implement in order to properly update the ListView on Ice Cream Sandwhich? Has anyone else encountered a similar problem?

What works for me is excellent until ICS.

+6
source share
1 answer

To fix this, I changed my code to the following:

 if(adapter != null) { adapter.getFilter().filter(aa1.getItem(item), new Filter.FilterListener() { public void onFilterComplete(int count) { adapter.notifyDataSetChanged(); if(lview3.getCount() == 0){ lview3.setVisibility(View.GONE); } else{ lview3.setVisibility(View.VISIBLE); decLayout.invalidate(); } }}); 

If decLayout is the relative layout that my list view is in, this seems to refresh the screen correctly when the data changes as a list.

While this works, I’m not 100% sure of its valid fix, and I would like to hear from anyone else who has problems similar to this and may have the correct fix.

0
source

Source: https://habr.com/ru/post/918375/


All Articles