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 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.
I also set:
android:dividerHeight="0dp" android:divider="#FFFFFF" Without success.
You can either write your own ListAdapter or subclass one of the existing ones.
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.
if you want to hide the item like this:
convertView.setLayoutParams(new AbsListView.LayoutParams(-1,1)); convertView.setVisibility(View.GONE); can't be AbsListView.LayoutParams(-1,0);
if convertview are reused you should add this below to set it height back:
if(convertView.getVisibility() == View.GONE) { convertView.setVisibility(View.VISIBLE); convertView.setLayoutParams(new AbsListView.LayoutParams(-1,-2)); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With