Search code examples
androidandroid-listviewandroid-cursoradapterandroid-listfragment

ListView doesn't refresh when last item is deleted


I have problem in my app. I have CursorLoader in conjcution with CursorAdapter. Everything works as expected, except one condition: when I have some items on ListView and I swap cursor in adapter for cursor that is empty, visible items aren't deleted (only dividers between rows disappear). When I touch ListView it disappears instantly.

Here is the situation. I have some non empty cursor: enter image description here

Then I swap for cursor that has no results: enter image description here

As you can see only dividers disappeard. After touching the screen both items disappear.

Here is my function that swaps cursor:

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor)
{
    ratesAdapter.swapCursor(cursor);
}

Fragment source: http://pastebin.com/N2YGzgRj

Please help me to solve this problem.


Solution

  • Okay, so after investigating problem a little bit more, I found that this problem only applies to Android 4.0.x. This bug doesn't exist in 2.2, 2.3 or 4.1, only 4.0. The only way for me to solve this bug is to add to onLoadFinished()

    getListView().setVisibility(View.GONE);
    getListView().setVisibility(View.VISIBLE);
    

    I don't find it elegant way, bu maybe you will have some ideas.