我有两种布局。我想将它们添加到 ExpandableListView 编程中。我曾尝试使用 ViewHolder 设置标签。但是当我尝试获取标签时总是 NullpointException。这是我的代码:
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;
}
}