可扩展的listview重复组数据Android

时间:2013-05-16 08:42:20

标签: java android expandablelistview expandablelistadapter

我有一个自定义BaseExpandableListAdapter,填充ExpandableListView工作正常。 这是我传递的列表具有这种结构结构:

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

    public class ChildList{
            String id,name;
    }

现在,我在类型为GroupList的Activity中创建一个列表,并将其传递给自定义适配器。 我遇到的问题是,当扩展expandViewView中的两个孩子时,其他孩子正在被复制/重复。

尝试调试此但失败了。我还将输入适配器类作为参考:

    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;
    }


}

0 个答案:

没有答案