Android Listview with different layout for each row?

后端 未结 2 386
梦谈多话
梦谈多话 2021-01-18 01:20

I want to create Listview in which I want different layout for all different row. Then how can I create custom adapter for set different layout for different row.

An

2条回答
  •  感动是毒
    2021-01-18 02:18

    create regular adapter , in the create_view function inflate the row xml layout according to the row type.

    for example

    @Override   
    public View getView(int position, View convertView, ViewGroup parent) {
         LayoutInflater inflater = (LayoutInflater) context
             .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
         if (position % 2 == 0 )
            xml_type = R.layout.row_one
         else
             xml_type = R.layout.row_two
    
         View rowView = inflater.inflate(xml_type, parent, false);
    }
    

提交回复
热议问题