如何读取ExpandaListView中的getChild

时间:2015-09-28 11:38:51

标签: android expandablelistview

我在

中有一个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方法时遇到了困难。 我有以下方法的错误

  

无法解析方法get('int')   无法解析方法('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();
}

1 个答案:

答案 0 :(得分:0)

我认为你搞砸了你的嵌套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();
    }
}