我没有堆叠的卡片视图。因此,每张卡片都设置了任务。因此,每张卡可能有不同的布局。我想知道如何膨胀不同的布局。
为此,我在字符串数组上创建了包含所有布局名称的字符串数组。
private ArrayList<String> LayOutData;
for (int x = 0; x < 4; x++) {
LayOutData.add("card_"+(x + 1));
}我要传递给适配器的这个LayOutData如下所示
mAdapter = new SwipeStackAdapter(mData,LayOutData);我的布局名称如下
card_1.xml
card_2.xml
card_3.xml
card_4.xml这是为视图设置布局的静态方式。
convertView = getLayoutInflater().inflate(R.layout.card_1, parent, false);但是我如何用卡片索引来膨胀我已经创建的名字呢?我对此的尝试如下。
switch (position){
case 0:
convertView = getLayoutInflater().inflate(R.layout.card_1, parent, false);
break;
case 1:
convertView = getLayoutInflater().inflate(R.layout.card_2, parent, false);
break;
case 2:
convertView = getLayoutInflater().inflate(R.layout.card_3, parent, false);
break;
case 3:
convertView = getLayoutInflater().inflate(R.layout.card_3, parent, false);
break;
default:
convertView = getLayoutInflater().inflate(R.layout.card_1, parent, false);
break;
}我知道这不是一种好的编码方式,你能给我一些建议吗?
https://stackoverflow.com/questions/41405808
复制相似问题