2 qq 36565195 qq_36565195 于 2017.01.12 10:03 提问

关于expandablelistview子项布局复用调用了父项复用的问题

我在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)

1个回答

qq_36565195
qq_36565195   2017.01.12 11:02

大神快来,求教啊!!!!!!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!