我想实现这样的东西 list photo 此列表包含每行中的不同控件,如单选按钮,微调器等。
答案 0 :(得分:1)
添加覆盖这些方法
@Override
public int getViewTypeCount() {
return super.getViewTypeCount();
}
和
@Override
public int getItemViewType(int position) {
return super.getItemViewType(position);
}
replace return super.getViewTypeCount();根据您打算使用的视图数量,然后在您的getView方法中,您可以从
修改视图if(convertView == null)
convertView = inflater.inflate(R.layout.row, null);
为:
if(convertView == null)
{
if(getItemViewType(position) == 0)
convertView = inflater.inflate(R.layout.row2, null);
}else{
convertView = inflater.inflate(R.layout.row2, null);}
注意:此问题必须已经回答,您应该发布您之前尝试过的代码。
答案 1 :(得分:0)
创建一个适配器并在getView()中实现一个处理正确布局和内容的算法
示例强>
public class MyAdapter extends ArrayAdapter {
private List<String> names;
public SimpleTextAdapter(Context context, List<String> names) {
super(context, R.layout.custom_row_simple_text, names);
this.names = names;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View customView = null;
if(position == 0){
customView = inflater.inflate(R.layout.layout_1, parent, false);
//Get Views from layout_1
TextView tv = (TextView) customView.findViewById(R.id.nameTv);
tv.setText(names.get(position));
}else if(){
customView = inflater.inflate(R.layout.layout_2, parent, false);
//Get Views of layout_2
}else{
customView = inflater.inflate(R.layout.layout_3, parent, false);
//_______,,_________
}
return customView;
}
}