Android:如何隐藏 ListView 项 [英] Android: How to hide a ListView Item
问题描述
如何隐藏 ListView 中的项目或至少将其高度设置为零?
How can you hide an item in a ListView or at least set its height to zero?
我已经尝试将视图的可见性设置为 GONE,但它仍然保持项目的空间(高度).
I have tried setting the visibility of the View to GONE but it still maintains the item's space (height).
推荐答案
重新提出一个老问题,但我刚刚遇到了这个问题,我想根据列表数据之外的条件暂时隐藏列表项.我最终做的是在 xml 中创建一个空项目"布局,并根据我的标准而不是 getView() 中的转换视图返回该布局...
Ressurecting an old question, but I just had this issue where I wanted to hide list items temporarily based upon criteria outside of the list data. What I ended up doing was creating a "null item" layout in xml and returned that based upon my criteria instead of the convert view in getView()...
我没有返回 convertView,而是返回了我的 null_item...
instead of returning the convertView, I returned my null_item...
return inflater.inflate(R.layout.null_item, null);
null_item.xml:
null_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
这篇关于Android:如何隐藏 ListView 项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!