androidlistviewandroid-listview

How to hide an item in a listview in Android


I know, this question was asked before, but I haven't seen a working answer for it.

Is there any way to hide some items in a ListView without changing source data?

I tried to set visibility of the item view to gone, it won't be displayed anymore, but the place reserved for this item is still there.

I also set:

android:dividerHeight="0dp"
android:divider="#FFFFFF"

Without success.


Solution

  • You can either write your own ListAdapter or subclass one of the existing ones.

    In your ListAdapter, you would simply filter out the items you do not want displayed by returning modified values for getCount(), getItem() and getItemId() as appropriate.