0
我想要實現這樣的事情 list photo 這個列表中包含像單選按鈕,微調等各行不同的控件列表視圖,每行有不同的看法
在自定義列表視圖適配器我想要實現這樣的事情 list photo 這個列表中包含像單選按鈕,微調等各行不同的控件列表視圖,每行有不同的看法
在自定義列表視圖適配器添加重寫這些方法
@Override
public int getViewTypeCount() {
return super.getViewTypeCount();
}
和
@Override
public int getItemViewType(int position) {
return super.getItemViewType(position);
}
替換返回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);}
注:這個問題必須得到回答,你應該發佈您之前嘗試過的代碼。
創建適配器和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;
}
}
除去資源推薦算法 –