丶渣渣 2017-01-12 02:03 采纳率: 28.6%
浏览 1734

关于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条回答

  • 丶渣渣 2017-01-12 03:02
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!