Android getChildView()中的ConvertView arg和getGroupView()在ExpandableAdapter中是混合的吗?

Android getChildView()中的ConvertView arg和getGroupView()在ExpandableAdapter中是混合的吗?,android,listview,expandablelistview,listadapter,expandable,Android,Listview,Expandablelistview,Listadapter,Expandable,调用getChildView()时,有时传递的convertView是我在getGroupView()中创建的视图,调用getGroupView()时,convertView有时是我在getChildView中创建的视图,为什么会发生这种情况 <code> public class FavoriteAdapter extends BaseExpandableListAdapter { private Context ctx; private int[] mGroups

调用getChildView()时,有时传递的convertView是我在getGroupView()中创建的视图,调用getGroupView()时,convertView有时是我在getChildView中创建的视图,为什么会发生这种情况

<code>
public class FavoriteAdapter extends BaseExpandableListAdapter {
    private Context ctx;
    private int[] mGroups;
    private List<Object>[] mChildren;

    public FavoriteAdapter(Context ctx) {
        this.ctx = ctx;
        mGroups = new int[0];
        mChildren = new List[0];
    }

    public void addAll(List<Object> list) {
        //mGroups=...
        //mChildren=...
        notifyDataSetChanged();
    }

    @Override
    public int getGroupCount() {
        return mGroups.length;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return mChildren[groupPosition].size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public int getChildTypeCount() {
        return mChildren.length;
    }

    @Override
    public int getChildType(int groupPosition, int childPosition) {
        return groupPosition;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return mGroups[groupPosition];
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return mChildren[groupPosition].get(childPosition);
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        ViewHolder h;
        if (null == convertView) {
            h = new ViewHolder();
            convertView = LayoutInflater.from(ctx).inflate(R.layout.group_item, null);
            h.tv1 = (TextView) convertView.findViewById(R.id.group_tv);
            convertView.setTag(h);
        } else {
            h = (ViewHolder) convertView.getTag();
        }
        switch ((Integer) getGroup(groupPosition)) {
            case Type.TYPE_1:
                h.tv1.setText("Type1");
                break;

            case Type.TYPE_2:
                h.tv1.setText("Type2");
                break;

            case Type.TYPE_3:
                h.tv1.setText("Type3");
                break;

            case Type.TYPE_4:
                h.tv1.setText("Type4");
                break;

            case Type.TYPE_5:
                h.tv1.setText("Type5");
                break;

            default:
                throw new RuntimeException("Group type does not match!!!");
        }

        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        Object p = getChild(groupPosition, childPosition);

        ViewHolder h;
        if (null == convertView) {
            h = new ViewHolder();
            switch (p.type) {
                case Type.TYPE_1:
                    convertView = LayoutInflater.from(ctx).inflate(R.layout.item_1, null);
                    h.img = (ImageView) convertView.findViewById(R.id.logo);
                    h.tv1 = (TextView) convertView.findViewById(R.id.title);
                    h.tv2 = (TextView) convertView.findViewById(R.id.intro);
                    break;

                case Type.TYPE_2:
                    convertView = LayoutInflater.from(ctx).inflate(R.layout.item_2, null);
                    h.img = (ImageView) convertView.findViewById(R.id.logo);
                    h.tv1 = (TextView) convertView.findViewById(R.id.title);
                    h.tv2 = (TextView) convertView.findViewById(R.id.intro);
                    break;

                case Type.TYPE_3:
                    convertView = LayoutInflater.from(ctx).inflate(R.layout.item_3, null);
                    h.tv1 = (TextView) convertView.findViewById(R.id.title);
                    h.tv2 = (TextView) convertView.findViewById(R.id.time);
                    break;

                case Type.TYPE_4:
                    convertView = LayoutInflater.from(ctx).inflate(R.layout.item_4, null);
                    h.img = (ImageView) convertView.findViewById(R.id.logo);
                    h.tv1 = (TextView) convertView.findViewById(R.id.title);
                    h.tv2 = (TextView) convertView.findViewById(R.id.addr);
                    h.tv3 = (TextView) convertView.findViewById(R.id.area);
                    break;

                case Type.TYPE_5:
                    convertView = LayoutInflater.from(ctx).inflate(R.layout.item_5, null);
                    h.img = (ImageView) convertView.findViewById(R.id.logo);
                    h.tv1 = (TextView) convertView.findViewById(R.id.title);
                    h.tv2 = (TextView) convertView.findViewById(R.id.addr);
                    h.tv3 = (TextView) convertView.findViewById(R.id.tel);
                    break;

                default:
                    throw new RuntimeException("Child type does not match!!!");
            }
            convertView.setTag(h);
        } else {
            h = (ViewHolder) convertView.getTag();
        }

        switch (p.type) {
            case Type.TYPE_1:
                if (null != p.thumb && p.thumb.length() != 0) {
                    displayImage(p.thumb, h.img);
                } else {
                    h.img.setVisibility(View.GONE);
                }
                if (null != p.title && p.title.length() != 0) {
                    h.tv1.setText(p.title);
                }
                if (null != p.detail && p.detail.length() != 0) {
                    h.tv2.setText(p.detail);
                }
                break;

            case Type.TYPE_2:
                if (null != p.thumb && p.thumb.length() != 0) {
                    displayImage(p.thumb, h.img);
                } else {
                    h.img.setVisibility(View.GONE);
                }
                if (null != p.title && p.title.length() != 0) {
                    h.tv1.setText(p.title);
                }
                if (null != p.intro) {
                    h.tv2.setText(p.intro);
                }
                break;

            case Type.TYPE_3:
                if (null != p.title && p.title.length() != 0) {
                    h.tv1.setText(p.title);
                }
                break;

            case Type.TYPE_4:
                if (null != p.thumb && p.thumb.length() != 0) {
                    displayImage(p.thumb, h.img);
                } else {
                    h.img.setVisibility(View.GONE);
                }
                if (null != p.title && p.title.length() != 0) {
                    h.tv1.setText(p.title);
                }
                break;

            case Type.TYPE_5:
                if (null != p.thumb && p.thumb.length() != 0) {
                    displayImage(p.thumb, h.img);
                } else {
                    h.img.setVisibility(View.GONE);
                }
                if (null != p.title && p.title.length() != 0) {
                    h.tv1.setText(p.title);
                }
                break;

            default:
                throw new RuntimeException("Child type does not match!!!");
        }

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    private void displayImage(String uri, ImageView img) {
        //display logo
    }

    private static class ViewHolder {
        ImageView img;
        TextView tv1;
        TextView tv2;
        TextView tv3;
    }
}

</code>

公共类FavoriteAdapter扩展了BaseExpandableListAdapter{
私有上下文ctx;
私人int[]管理组;
私人名单[]儿童;
公共收藏夹适配器(上下文ctx){
this.ctx=ctx;
mGroups=newint[0];
mChildren=新列表[0];
}
公共void addAll(列表){
//mGroups=。。。
//McChildren=。。。
notifyDataSetChanged();
}
@凌驾
public int getGroupCount(){
返回mGroups.length;
}
@凌驾
公共整数getChildrenCount(整数组位置){
返回mChildren[groupPosition].size();
}
@凌驾
公共长getGroupId(int-groupPosition){
返回组位置;
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回子位置;
}
@凌驾
public int getChildTypeCount(){
返回mChildren.length;
}
@凌驾
public int getChildType(int groupPosition,int childPosition){
返回组位置;
}
@凌驾
公共对象getGroup(int-groupPosition){
返回管理组[groupPosition];
}
@凌驾
公共对象getChild(int-groupPosition,int-childPosition){
返回mChildren[groupPosition].get(childPosition);
}
@凌驾
公共视图getGroupView(int groupPosition、布尔isExpanded、视图convertView、视图组父级){
视窗座h;
if(null==convertView){
h=新的视窗支架();
convertView=LayoutFlater.from(ctx).充气(R.layout.group_项,空);
h、 tv1=(TextView)convertView.findViewById(R.id.group\u tv);
convertView.setTag(h);
}否则{
h=(ViewHolder)convertView.getTag();
}
开关((整数)getGroup(groupPosition)){
案例类型。案例类型_1:
h、 tv1.setText(“Type1”);
打破
案例类型。案例类型2:
h、 tv1.setText(“Type2”);
打破
案例类型。案例类型3:
h、 tv1.setText(“Type3”);
打破
案例类型。案例类型4:
h、 tv1.setText(“Type4”);
打破
案例类型。案例类型_5:
h、 tv1.setText(“Type5”);
打破
违约:
抛出新的运行时异常(“组类型不匹配!!!”;
}
返回视图;
}
@凌驾
公共视图getChildView(int-groupPosition、int-childPosition、布尔isLastChild、视图convertView、视图组父级){
对象p=getChild(groupPosition,childPosition);
视窗座h;
if(null==convertView){
h=新的视窗支架();
开关(p型){
案例类型。案例类型_1:
convertView=LayoutFlater.from(ctx).充气(R.layout.item_1,空);
h、 img=(ImageView)convertView.findViewById(R.id.logo);
h、 tv1=(TextView)convertView.findViewById(R.id.title);
h、 tv2=(TextView)convertView.findViewById(R.id.intro);
打破
案例类型。案例类型2:
convertView=LayoutFlater.from(ctx).充气(R.layout.item_2,空);
h、 img=(ImageView)convertView.findViewById(R.id.logo);
h、 tv1=(TextView)convertView.findViewById(R.id.title);
h、 tv2=(TextView)convertView.findViewById(R.id.intro);
打破
案例类型。案例类型3:
convertView=LayoutFlater.from(ctx).充气(R.layout.item_3,空);
h、 tv1=(TextView)convertView.findViewById(R.id.title);
h、 tv2=(TextView)convertView.findViewById(R.id.time);
打破
案例类型。案例类型4:
convertView=LayoutFlater.from(ctx).充气(R.layout.item_4,空);
h、 img=(ImageView)convertView.findViewById(R.id.logo);
h、 tv1=(TextView)convertView.findViewById(R.id.title);
h、 tv2=(TextView)convertView.findViewById(R.id.addr);
h、 tv3=(TextView)convertView.findViewById(R.id.area);
打破
案例类型。案例类型_5:
convertView=LayoutFlater.from(ctx).充气(R.layout.item_5,空);
h、 img=(ImageView)convertView.findViewById(R.id.logo);
h、 tv1=(TextView)convertView.findViewById(R.id.title);
h、 tv2=(TextView)convertView.findViewById(R.id.addr);
h、 tv3=(TextView)convertView.findViewById(R.id.tel);
打破
违约:
抛出新的RuntimeException(“子类型不匹配!!!”;
}
convertView.setTag(h);
}否则{
h=(ViewHolder)convertView.getTag();
}
开关(p型){
案例类型。案例类型_1:
if(null!=p.thumb&&p.thumb.length()!=0){
显示图像(p.thumb,h.img);
}否则{
h、 img.setVisibility(View.GONE);
}
if(null!=p.title&&p.title.length()!=0){
h、 tv1.setText(p.title);
}
if(null!=p.detail&&p.detail.length()!=0){
h、 tv2.setText(p.detail);
}
打破
案例类型。案例类型2:
if(null!=p.thumb&&p.thumb.length()!=0){
显示图像(p.thumb,h.img);