Inflate layout on ListItem based on ListItem specific variable

后端 未结 2 425
不知归路
不知归路 2021-01-12 09:18

I\'m using a SimpleCursorAdapter and a ListView to show some data loaded with a Loader. Inside the cursor I have items with a in

2条回答
  •  时光说笑
    2021-01-12 09:47

    I think you only need to inflate the right layout on your getView(int position, View convertView, ViewGroup parent) method:

    MyItem item = getItem(position);
    View vi = convertView;
    if(vi == null){
        switch(item.getStatus())
        {
            case 0:
                vi = mInflater.inflate(R.layout.item1, null);
                break;
            case 1:
                vi = mInflater.inflate(R.layout.item2, null);
                break;
            case 2:
                vi = mInflater.inflate(R.layout.item3, null);
                break;
        }
        //set viewholder ...
    }else{
        //get viewholder ...
    }
    // set values to views ...
    

    Is this what you needed?

提交回复
热议问题