我有一个自定义 BaseExpandableListAdapter,填充 ExpandableListView 工作正常。这是我传递的列表,具有以下结构:
public Class GroupList{
String id,name;
List<ChildList> childList;
}
public class ChildList{
String id,name;
}
现在我在我的 GroupList 类型的 Activity 中创建一个列表并将其传递给自定义适配器。我遇到的问题是,当展开可扩展列表视图中的两个孩子时,其他孩子正在被复制/重复。
一直在尝试调试它但失败了。我还将在适配器类中放入以供参考:
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;
}
}