DolDurma
DolDurma

Reputation: 17289

Android how to use different layouts for each listview item

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

Upvotes: 1

Views: 112

Answers (1)

Md Abdul Gafur
Md Abdul Gafur

Reputation: 6201

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;
    }

Upvotes: 1

Related Questions