如何隐藏在Android的列表视图中的项目视图、项目、列表、Android

2023-09-13 00:22:22 作者:留不住的人我送你走

我知道,这个问题被问过,但我还没有看到这一个工作的答案。

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

有没有办法隐藏在的ListView 部分项目在不改变源数据?

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.

我还设置:

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

但没有成功。

Without success.

推荐答案

您可以编写自己的ListAdapter或子类的现有之一。

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

在你ListAdapter,你只会过滤掉不希望显示的项目通过为getCount将(),getItem()时和getItemId()适当返回修改后的值。

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.