如何在Android的列表视图中隐藏项目 [英] How to hide an item in a listview in Android

查看:37
本文介绍了如何在Android的列表视图中隐藏项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,之前有人问过这个问题,但我还没有看到有效的答案.

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"

没有成功.

推荐答案

您可以编写自己的 ListAdapter 或子类化现有的其中之一.

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

在您的 ListAdapter 中,您只需通过返回 getCount()getItem() 的修改值来过滤掉不想显示的项目code> 和 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.

这篇关于如何在Android的列表视图中隐藏项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆