2016-07-20 11 views

回答

1

添加重寫這些方法

@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);} 

注:這個問題必須得到回答,你應該發佈您之前嘗試過的代碼。

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; 
     } 
    } 
相關問題