簡體   English   中英

如何在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方法時遇到困難。 我遇到以下方法的錯誤

無法解析方法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();
}

我認為您搞砸了嵌套的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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM