views:

50

answers:

2

I have a listview that's using a custom adapter. I want to dynamically show/remove items from the listview. I've tried everything inside the getView() method in my view adapter. I've tried doing setVisiblity(View.GONE) on the view I'm returning. And it infact doesn't draw the view, but it allocates space for the view and it's just a blank black space.

Is this even possible to set items in listview invisible?

A: 

You need to call setVisiblity(View.GONE) on the returned view and all the views inside it. If you are reusing the convert view passed in you need to remember to call setVisiblity(View.VISIBLE) on all the views you want visible.

If you have a lot of invisible views you may need to set the divider height to 0 and add your own divider to the returned views. Otherwise the 'invisible' views will each have a visible divider and produce a noticeable gray line between visible views.

Peter
+1  A: 

If you want to remove items from the ListView I would change the values that the associated ListAdapter returns rather than trying to manipulate the views.

Dave Webb
Yes, instead of messing with the visibility, just remove them entirely.
st0le
I ended up creating 2 arrayLists and just shuttling my items back and forth (one complete list, and one displayed list)
Falmarri