How to hide an item in a listview in Android

后端 未结 11 1069
天涯浪人
天涯浪人 2020-12-03 07:15

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

11条回答
  •  生来不讨喜
    2020-12-03 07:42

    For me a simple solution was to create my own adapter with a custom row layout, containing a wrapper of all content (e.g. LinearLayout), and set this wrapper visibility to View.GONE in the adapter's getView() method, when I did not want that item shown. No need to modify the data set or maintain two lists. When creating the ListView, I also set it to not automatically show dividers:

        android:divider="@null"
        android:dividerHeight="0dp"
    

    and draw my own divider (which I also set to GONE when I don't want that item). Otherwise you'd see multiple dividers or a thick gray line where multiple items were hidden.

提交回复
热议问题