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

5 Answers 5

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

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!
solved the issue by using code from stackoverflow.com/questions/1914477/…
4

Inflate a View and setVisibility to VIEW.GONE

1 Comment

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 :-/...
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();

Comments

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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.