Making a view in a listview invisible android
I have a ListView
that's using a custom adapter. I want to dynamically add/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 in fact doesn't draw the view, but it still allocates space for the view and it's just a blank black space.
Is this even possible to set items in ListView
invisible?
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.
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.
精彩评论