Search code examples
androidlistviewlistadapter

Return empty row in Custom ArrayAdapter?


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


Solution

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