1

In my application I can only use the same layout for each listview item in each row. This is not what I want for my application and I would like to have a different layout for each of the listview items.

As an example of what I would like to achieve please see the screenshot below.

different layout each listview items

1
  • 1
    create two different rows in xml. In your custom adapter class use view holder to store the inflated objects, select the rows as per your need in the adapter. Commented Feb 3, 2015 at 9:15

1 Answer 1

1

You can do it via android Listview BaseAdapter. In BaseAdapter getView method, you can added code like this.

public View getView(final int position, View convertView, ViewGroup parent) {
        if(item1 or your condition)
        {
            convertView=inflater.inflate(R.layout.from_right_row.xml, parent, false);
        }else if(item2 or your condition) {
            convertView=inflater.inflate(R.layout.from_left_row.xml, parent, false);
        }

        return convertView;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

This is not a good way to inflate views. Avoid passing null as the parent view.

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.