2013-09-23 17 views
0

我有兩種佈局。我想將它們添加到ExpandableListView編程中。我嘗試使用ViewHolder.But設置Tab,當我嘗試getTag時,它始終是NullpointException。這裏是我的代碼:如何將不同的佈局添加到BaseAdapter中?

 SeekBarHolder sh=null; 
     TickHolder th=null; 
     if(convertView==null){ 
      switch((Integer)childData.get(groupPosition).get(childPosition).get("type")){ 
      case ProtocolConst.EXPANDABLE_CHILD_TYPE_SEEKBAR: 
       sh=new SeekBarHolder(); 
       convertView=inflater.inflate(R.layout.fragment_left_listview_child_seekbar_item, null); 
       sh.text=(TextView)convertView.findViewById(R.id.Left_ExpandableListView_Child_SeekBar_TextView); 
       sh.seekbar=(SeekBar)convertView.findViewById(R.id.Left_ExpandableListView_Child_SeekBar_SeekBar); 
       convertView.setTag(sh); 

      case ProtocolConst.EXPANDABLE_CHILD_TYPE_TICK: 
       th=new TickHolder(); 
       convertView=inflater.inflate(R.layout.fragment_left_listview_child_seekbar_item, null); 
       th.text=(TextView)convertView.findViewById(R.id.Left_ExpandableListView_Child_Tick_TextView); 
       th.tick=(ImageView)convertView.findViewById(R.id.Left_ExpandableListView_Child_Tick_ImageView); 
       convertView.setTag(th); 

      }}else{ 
      switch((Integer)childData.get(groupPosition).get(childPosition).get("type")){ 
      case ProtocolConst.EXPANDABLE_CHILD_TYPE_SEEKBAR: 
       sh=(SeekBarHolder)convertView.getTag(); 
       break; 
      case ProtocolConst.EXPANDABLE_CHILD_TYPE_TICK: 
       th=(TickHolder)convertView.getTag(); 
       break; 
      } 
} 

回答

1

你應該增加額外的方法給你的加法器。適配器以其他方式使用不同的佈局。使用mehod getViewTypeCount(){告訴適配器將使用多少個視圖,getItemViewType(int position)在getViewMethod中的視圖之間切換。

另外爲ExpadnableListView你應該使用其他方法,它允許你使用爲你的列表添加其他佈局。

相關問題