[英]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! 我认为您搞砸了嵌套的get
和size
,保持简单!
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.