我在getgroupview里面设置的是复用,子项也是需要复用的,但是子项的复用一直会调
用父项里面的,但是我tag设置的明明就是子项的holder,以下是代码,希望大神帮忙一下,急
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
int Type = getGroupType(groupPosition);
switch (Type){
case GROUP_TYPE_ONE:
if (convertView == null){
convertView = LayoutInflater.from(mContext).inflate(R.layout.list_category_item,null);
}
TextView textView = (TextView) convertView.findViewById(R.id.list_category_name);
textView.setText((Integer) getGroup(groupPosition));
textView.setTextSize(20);
break;
case GROUP_TYPE_TWO:
GroupHolder groupHolder;
if (convertView == null){
groupHolder = new GroupHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.expand_group_layout,null);
groupHolder.mGroupImg = (ImageView) convertView.findViewById(R.id.FAQ_list_item_image);
groupHolder.mGroupNomalImg = (ImageView) convertView.findViewById(R.id.FAQ_list_cancle_image);
groupHolder.mGroupText = (TextView) convertView.findViewById(R.id.FAQ_list_item_text);
groupHolder.mGroupRela = (RelativeLayout) convertView.findViewById(R.id.FAQ_list_item_image_main);
convertView.setTag(groupHolder);
}else{
groupHolder = (GroupHolder) convertView.getTag();
Log.e(TAG,convertView.getTag().toString()+"groupview");
}
ItemValue itemValue = (ItemValue) getGroup(groupPosition);
groupHolder.mGroupText.setText(itemValue.getmMainContent());
groupHolder.mGroupImg.setImageResource(R.mipmap.faq_icon);
if (isExpanded){
groupHolder.mGroupNomalImg.setImageResource(R.mipmap.status_enter_p);
}else {
groupHolder.mGroupNomalImg.setImageResource(R.mipmap.status_enter);
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(CCIApplication.getScreenHeight(20),CCIApplication.getScreenHeight(20));
groupHolder.mGroupRela.setLayoutParams(params);
groupHolder.mGroupNomalImg.setLayoutParams(params);
break;
}
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
//View view = convertView;
ChildHolder childHolder ;
if (convertView == null){
childHolder = new ChildHolder();
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.child_text_layout,null);
childHolder.mChildText = (TextView) convertView.findViewById(R.id.child_text);
convertView.setTag(childHolder);
}else{
Log.e(TAG,convertView.getTag()+"childview");
childHolder = (ChildHolder) convertView.getTag();
}
ItemValue itemValue = (ItemValue) getChild(groupPosition,childPosition);
childHolder.mChildText.setText(itemValue.getmMainContent());
return convertView;
}
当执行childHolder = (ChildHolder) convertView.getTag();这一句时,返回的是grouphlder
报错log如下:
01-12 10:14:10.025 31271-31271/cci.com.soundmax.hk E/Expandable: cci.com.soundmax.hk.setting.adapter.MyExpandableAdapter$GroupHolder@b797a7egroupview
01-12 10:14:10.035 31271-31271/cci.com.soundmax.hk E/Expandable: cci.com.soundmax.hk.setting.adapter.MyExpandableAdapter$GroupHolder@9624af5childview
01-12 10:14:10.045 31271-31271/cci.com.soundmax.hk E/AndroidRuntime: FATAL EXCEPTION: main
Process: cci.com.soundmax.hk, PID: 31271
java.lang.ClassCastException: cci.com.soundmax.hk.setting.adapter.MyExpandableAdapter$GroupHolder cannot be cast to cci.com.soundmax.hk.setting.adapter.MyExpandableAdapter$ChildHolder
at cci.com.soundmax.hk.setting.adapter.MyExpandableAdapter.getChildView(MyExpandableAdapter.java:244)