如何读取 ExpandaListView 中的 getChild

How to read the getChild in the ExpandaListView

我在

中有一个 expandableListAdapter
    public class ExpandableListAdapter extends BaseExpandableListAdapter

{
    private Context context;
    private List<String> listdataheader;
    private HashMap<String, Products> listdatachild;
    public ExpandableListAdapter(Context context,ArrayList<Products> fList)
    {
        HashMap<String, Products> listDataChild = new HashMap<String, Products>();
        for (Products data : fList) {
            listdatachild.put(data.Name, data);
        }

        List<String> listdataheader = new ArrayList<String>();
        for (Products data: fList) {
            listdataheader.add(data.Name);
        }

        this.context=context;
        this.listdataheader=listdataheader;
        this.listdatachild=listDataChild;
    }

我在重写 getChild、getChildrenCount 方法时遇到困难。 我遇到以下方法的错误

Cannot resolve method get('int') Cannot resolve method ('size')

 @Override
    public Object getChild(int groupPosition, int childPosition) {
        return this.listdatachild.get(this.listdataheader.get(groupPosition)).get(childPosition);
    }

@Override
public int getChildrenCount(int groupPosition) {
    // TODO Auto-generated method stub
    return this.listdatachild.get(this.listdataheader.get(groupPosition)).size();
}

我认为您搞砸了嵌套的 getsize,保持简单!

我会做这样的事情:

 public class ExpandableListAdapter extends BaseExpandableListAdapter{
    private Context context;
    private List<String> listdataheader = new ArrayList<String>();
    private HashMap<String, Products> listdatachild = new HashMap<String, Products>();
    public ExpandableListAdapter(Context context,ArrayList<Products> fList)
    {
        for (Products data : fList) {
            listdatachild.put(data.Name, data);
        }

        for (Products data: fList) {
            listdataheader.add(data.Name);
        }

        this.context=context;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return listdatachild.get(this.listdataheader.get(groupPosition);
    }

    @Override
    public int getChildrenCount(int groupPosition) {
    return listdatachild.size();
    }
}