4

when my ListView is being filled by a custom Array Adapter, I check for a certain parameter in the current list item, and if it is false, I want to return an empty row. At the moment, I am doing this by inflating an empty xml file, but that creates ugly list item dividers when a number of items should not be shown, and is obviously not the best way ;-)!

    if (list.get(position).equals("i-dont-want-this-in-the-list-view")){
        View empty=inflater.inflate(R.layout.empty_row, parent, false);
        return(empty);
    }

I have tried to return "null", but it clearly expects a View to be returned. Is there anything I could do without having to filter the list that is being used for the ListView beforehand (I want to keep it intact as I am doing other things with it, too).

Thanks,

Nick

Nick
  • 3,504
  • 2
  • 39
  • 78

5 Answers5

6

To fix the issue of line dividers, remove the line dividers from the ListView and put your own in inside the individual items.

user705142
  • 461
  • 5
  • 18
  • Wow, that's an awesome - but at the same time very obvious - suggestion. I feel stupid for not having thought of this myself. Thanks very much! – Nick Jun 11 '11 at 05:04
  • 1
    solved the issue by using code from http://stackoverflow.com/questions/1914477/how-to-remove-line-inbetween-two-listviews-in-android – patrics Apr 30 '14 at 12:17
4

Inflate a View and setVisibility to VIEW.GONE

Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • 1
    Thanks for your answer! Your suggestion doesn't stop the gray list-item dividers from piling up when a lot of items in a list are being hidden with `VIEW.GONE` (which is what I wanted to do), but i guess there isn't a way to do this :-/... – Nick Jul 25 '10 at 22:51
1

What's about:

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
   //use a global Array to set the rows visible/hidden and return empty rows
   if(disArray[position] == false) return new View(getContext()); 

   ... // continue with your getView() implementation
   return convertView;
}

to update the ListView use

adapter.notifyDataSetChanged();
lx222
  • 248
  • 1
  • 16
0

What're in the rows that aren't empty? Images can be replaced by empty, transparent pngs and text views can be set to "", etc.

Pedantic
  • 5,032
  • 2
  • 24
  • 37
0

View.Gone will give u empty list row. try using layout params and set to zero value like this:

FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(0,0); viewholder.programRow.setLayoutParams(layoutParams);

Layoutparams should be used as according to parent viewgroup used

Zoombie
  • 3,590
  • 5
  • 33
  • 40