Android: How to hide a ListView Item

Tawani picture Tawani · Apr 14, 2010 · Viewed 32.1k times · Source

How can you hide an item in a ListView or at least set its height to zero?

I have tried setting the visibility of the View to GONE but it still maintains the item's space (height).

Answer

Tonithy picture Tonithy · May 29, 2013

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()...

instead of returning the convertView, I returned my null_item...

return inflater.inflate(R.layout.null_item, null);

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>