Java 重复标头时BaseExpandableListAdapter获取子视图

Java 重复标头时BaseExpandableListAdapter获取子视图,java,android,Java,Android,我已经创建了一个可扩展列表适配器,并且我正在尝试访问我要传入的对象(例如id)的属性(CoolObject) 问题是,我传递给列表适配器的头(在listDataHeader中)可能与另一个头的字符串相同,但显然具有不同的对象属性。我如何解决这个问题 例如,this.\u listDataHeader可能包含“CoolObjectOne”、“CoolObjectOne”。如果我尝试getChild,它将返回第一个对象的属性(例如id),而不考虑groupPosition/childPosition

我已经创建了一个可扩展列表适配器,并且我正在尝试访问我要传入的对象(例如id)的属性(CoolObject)

问题是,我传递给列表适配器的头(在listDataHeader中)可能与另一个头的字符串相同,但显然具有不同的对象属性。我如何解决这个问题

例如,
this.\u listDataHeader
可能包含“CoolObjectOne”、“CoolObjectOne”。如果我尝试
getChild
,它将返回第一个对象的属性(例如id),而不考虑groupPosition/childPosition

ExpandableListAdapter.java

public class ExpandableListAdapter extends BaseExpandableListAdapter {

private Context _context;
private List<String> _listDataHeader; 
private HashMap<String, List<CoolObject>> _listDataChild;

public ExpandableListAdapter(Context context, List<String> listDataHeader,
                                      HashMap<String, List<CoolObject>> listChildData) {

    this._context = context;
    this._listDataHeader = listDataHeader;
    this._listDataChild = listChildData;
}

@Override
public Object getChild(int groupPosition, int childPosititon) {

    return this._listDataChild.get(this._listDataHeader.get(groupPosition))
            .get(childPosititon);
}

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

@Override
public View getChildView(int groupPosition,
                         final int childPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        convertView = infalInflater.inflate(R.layout.live_final_list_item, null);
    }

    CoolObject co = (CoolObject) getChild(groupPosition, childPosition); // this is where the duplicate heading issue is

    // return cool object name 
    coolObjectName.setText(lv.getName());

    // return cool object id
    coolObjectId.setText(lv.getId());

    return convertView;
}

@Override
public int getChildrenCount(int groupPosition) {
    return this._listDataChild.get(this._listDataHeader.get(groupPosition))
            .size();
}

@Override
public Object getGroup(int groupPosition) {
    try {
        return this._listDataHeader.get(groupPosition);
    } catch (Exception e) {
        e.getMessage();
        return "";
    }
}

@Override
public int getGroupCount() {
    try {
        return this._listDataHeader.size();
    } catch (Exception e) {
        return 0;
    }
}

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

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
                         View convertView, ViewGroup parent) {

    String headerTitle = (String) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.competition_list_group, null);
    }

    TextView lblListHeader = (TextView) convertView
            .findViewById(R.id.lblListHeader);
    lblListHeader.setTypeface(null, Typeface.BOLD);
    lblListHeader.setText(headerTitle);

    return convertView;
}

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

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

// constructor
public CoolObject(String name, String id) {
    this.id = id;
    this.name = name;
}

public void setId(String id) {
    this.id = id;
}

public String getId() {
    return id;
}

public void setName(String name) {
    this.name = name;
}

public String getName() {
    return name;
}

}