Java 可扩展列表视图重复组数据

Java 可扩展列表视图重复组数据,java,android,expandablelistview,expandablelistadapter,Java,Android,Expandablelistview,Expandablelistadapter,我有一个自定义的BaseExpandableListAdapter,填充ExpandableListView很好。 这是我要传递的列表,其结构如下: public Class GroupList{ String id,name; List<ChildList> childList; } public class ChildList{ String id,name; } 公共类组

我有一个自定义的BaseExpandableListAdapter,填充ExpandableListView很好。 这是我要传递的列表,其结构如下:

    public Class GroupList{
            String id,name;
            List<ChildList> childList;
    }

    public class ChildList{
            String id,name;
    }
公共类组列表{
字符串id、名称;
儿童名单;
}
公共类儿童名单{
字符串id、名称;
}
现在,我在活动中创建了一个GroupList类型的列表,并将其传递给自定义适配器。 我遇到的问题是,当展开expandableListView中的两个子项时,其他子项会被复制/重复

正在尝试调试此文件,但失败。我还将放入适配器类以供参考:

    public class ADPTPresetsExpandableList extends BaseExpandableListAdapter {

        private Activity activity;
        private List<GroupList> groupList;
    Button btElvPresets;
    public ADPTPresetsExpandableList(Activity pContext,List<GroupList> groupList) {
        if(pContext != null)this.activity = pContext;
        if (groupList != null)this.groupList = groupList;

    }

    @Override
    public Object getChild(int groupPos, int childPos) {
        // TODO Auto-generated method stub
        return groupList.get(groupPos).getChildList().get(childPos);
    }

    @Override
    public long getChildId(int groupPos, int childPos) {
        return childPos;
    }

    @Override
    public View getChildView(int grpPos, int childPos, boolean arg2, View childView,ViewGroup arg4) {


            if(getChild(grpPos, childPos)!=null){
                ChildList childNode = (ChildList)getChild(grpPos, childPos);

                childView = LayoutInflater.from(activity).inflate(R.layout.expandablelistview_presets_child, null);

                TextView tvChildPresetTitle = (TextView)childView.findViewById(R.id.tvPresetChildTitle);
                tvChildPresetTitle.setText(childNode.getName());

            }



        return childView;
    }

    @Override
    public int getChildrenCount(int arg0) {
        // TODO Auto-generated method stub
        return groupList.get(arg0).getChildList().size();
    }

    @Override
    public Object getGroup(int arg0) {
        // TODO Auto-generated method stub
        return groupList.get(arg0);
    }

    @Override
    public int getGroupCount() {
        // TODO Auto-generated method stub
        return groupList.size();
    }

    @Override
    public long getGroupId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getGroupView(int pos, boolean arg1, View groupView, ViewGroup arg3) {
        // TODO Auto-generated method stub
        if (groupView == null){

            GroupList groupList =(GroupList) getGroup(pos);
            groupView = activity.getLayoutInflater().inflate(R.layout.expandablelistview_presets_group,null);
            TextView tvChildPresetTitle = (TextView)groupView.findViewById(R.id.tvPresetChildTitle);
            tvChildPresetTitle.setText(groupList.getName());

            }
        return groupView;
    }

    @Override
    public boolean hasStableIds() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isChildSelectable(int arg0, int arg1) {
        // TODO Auto-generated method stub
        return false;
    }


}
公共类AdptPresetExpandableList扩展了BaseExpandableListAdapter{
私人活动;
私有列表组列表;
按钮预设;
公共AdptPresetExpandableList(活动pContext,列表组列表){
如果(pContext!=null)this.activity=pContext;
如果(groupList!=null)this.groupList=groupList;
}
@凌驾
公共对象getChild(int-groupPos,int-childPos){
//TODO自动生成的方法存根
返回groupList.get(groupPos.getChildList().get(childPos);
}
@凌驾
公共长getChildId(int-groupPos,int-childPos){
返回childPos;
}
@凌驾
公共视图getChildView(int-grpPos、int-childPos、布尔值arg2、视图子视图、视图组arg4){
if(getChild(grpPos,childPos)!=null){
ChildList childNode=(ChildList)getChild(grpPos,childPos);
childView=LayoutFlater.from(活动)。充气(R.layout.expandablelistview\u预设\u子对象,空);
TextView tvChildPresetTitle=(TextView)childView.findViewById(R.id.tvChildPresetTitle);
tvChildPresetTitle.setText(childNode.getName());
}
返回儿童视图;
}
@凌驾
公共整数getChildrenCount(整数arg0){
//TODO自动生成的方法存根
返回groupList.get(arg0.getChildList().size();
}
@凌驾
公共对象getGroup(int arg0){
//TODO自动生成的方法存根
返回groupList.get(arg0);
}
@凌驾
public int getGroupCount(){
//TODO自动生成的方法存根
返回groupList.size();
}
@凌驾
公共长getGroupId(int arg0){
//TODO自动生成的方法存根
返回arg0;
}
@凌驾
公共视图getGroupView(int-pos、布尔值arg1、视图组视图、视图组arg3){
//TODO自动生成的方法存根
if(groupView==null){
GroupList GroupList=(GroupList)getGroup(pos);
groupView=activity.GetLayoutFlater().inflate(R.layout.expandablelistview\u预设组,null);
TextView tVColdPresetTitle=(TextView)groupView.findViewById(R.id.tVColdPresetTitle);
tvChildPresetTitle.setText(groupList.getName());
}
返回组视图;
}
@凌驾
公共布尔表ID(){
//TODO自动生成的方法存根
返回false;
}
@凌驾
公共布尔值isChildSelectable(int arg0,int arg1){
//TODO自动生成的方法存根
返回false;
}
}

您对onClick做过任何更改吗?我在想,在这种情况下,可能是一个逻辑错误导致了这个问题。否则,我建议你开始在你的设备上调试,然后一步一步地检查到底发生了什么。在类AdptPresetExpandableList.ya中的所有函数上加一个断点。我调试并发现了错误,这确实是非常愚蠢的。但是仍然不能确定问题产生的原因,这个空检查就是问题所在:if(groupView==null)。。谢谢你的回复,非常感谢……我想我理解了整个问题。get view方法仅在groupView/childView为null的情况下返回更新的视图。太好了。将解决方案提交到您的帖子中,以便以后可以将其标记为已解决。