Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android set View.GONE does not "release" space in listview

I have a listview with some items that can be marked as "done". There is also a togglebutton that says "hide done items".

However, when I do hide the items by setting setVisibility(View.GONE) there is still space left in the list..

Should not be that hard to toggle list items in a listview?

like image 790
Peter Berkenbosch Avatar asked Oct 27 '11 14:10

Peter Berkenbosch


3 Answers

Changing the android:layout_height="wrap_content" to android:layout_height="fill_parent" fixed the issue.. was testing with a long list.. with a short list the same space was above the list.. Stupid mistake..

Thanks all for help.. everything is working now.

like image 70
Peter Berkenbosch Avatar answered Nov 08 '22 03:11

Peter Berkenbosch


Are you trying to hide the whole list item? If so I guess that the list view won't like that because it is still calculating with the same amount of items. I don't think it will just ignore it because it's gone.

The clean solution would be to return another getCount and just ignore the items you want to hide. Or remove items from the internal used list. Call notifyDataSetChanged on the adapter when you modified the amount of items in the list.

like image 22
Knickedi Avatar answered Nov 08 '22 01:11

Knickedi


you should operate on the list adapter also...

like image 39
Iulia Barbu Avatar answered Nov 08 '22 01:11

Iulia Barbu