简体   繁体   English

如何在ExpandaListView中读取getChild

[英]How to read the getChild in the ExpandaListView

I have an expandableListAdapter in 我在其中有一个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;
    }

I am having difficulty in rewriting the getChild, getChildrenCount methods. 我在重写getChild,getChildrenCount方法时遇到困难。 I am having the errors for the following methods 我遇到以下方法的错误

Cannot resolve method get('int') Cannot resolve method ('size') 无法解析方法get('int')无法解析方法('size')

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

and

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

I think you messed up with your nested get and size , keep it simple! 我认为您搞砸了嵌套的getsize ,保持简单!

I would have done something like this: 我会做这样的事情:

 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.

相关问题 如何在Robotium中使用getChild? - How to use getChild in robotium? ExpandableListAdapter.getChild()中的NullPointerException - NullPointerException at ExpandableListAdapter.getChild() getReference() 与 getChild() - getReference() vs. getChild() getChild()方法出错 - getChild() method makes error GetChild方法中的数组大小在ExpandableListView中是错误的 - Array size in GetChild method is wrong in ExpandableListView Android:getChild()在ExpandableListView中单击按钮时的EditText值 - Android : getChild() EditText values on button click in ExpandableListView 由于AccessibilityNodeInfo getChild而获得大量ANR - Getting Lots of ANR due to AccessibilityNodeInfo getChild 为什么在BaseExpandableListAdapter中的getchild方法从每个孩子调用两次? - why getchild method in BaseExpandableListAdapter calling two times from each child? 为什么在我的应用中,方法getChild,getChildId和getChildView无法执行 - Why in my app the methods getChild, getChildId and getChildView doesn't execute 当滚动列表时,RecyclerView.getChild(index)显示null(索引搞砸了) - RecyclerView.getChild(index) shows null when list is scrolled (index gets messed up)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM