如何读取ExpandaListView的getChild [英] How to read the getChild in the ExpandaListView
本文介绍了如何读取ExpandaListView的getChild的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在
的expandableListAdapter 公共类ExpandableListAdapter扩展BaseExpandableListAdapter{
私人上下文的背景下;
私人列表<串GT; listdataheader;
私人的HashMap<弦乐,产品> listdatachild;
公共ExpandableListAdapter(上下文的背景下,ArrayList的<产品> FLIST)
{
HashMap的<弦乐,产品> listDataChild =新的HashMap<弦乐,产品>();
对于(产品数据:FLIST){
listdatachild.put(data.Name,数据);
} 清单<串GT; listdataheader =新的ArrayList<串GT;();
对于(产品数据:FLIST){
listdataheader.add(data.Name);
} this.context =背景;
this.listdataheader = listdataheader;
this.listdatachild = listDataChild;
}
我有在重写getChild,getChildrenCount方法的难度。
我有以下方法错误
无法解析方法来获取('廉政')
无法解析的方法('大小')
块引用>@覆盖
公共对象getChild(INT groupPosition,诠释childPosition){
返回this.listdatachild.get(this.listdataheader.get(groupPosition))获得(childPosition)。
}和
@覆盖
公众诠释getChildrenCount(INT groupPosition){
// TODO自动生成方法存根
返回this.listdatachild.get(this.listdataheader.get(groupPosition))的大小()。
}
解决方案我觉得你搞砸了你的嵌套
GET
和尺寸
,保持它的简单!我会做这样的事情:
公共类ExpandableListAdapter扩展BaseExpandableListAdapter {
私人上下文的背景下;
私人列表<串GT; listdataheader =新的ArrayList<串GT;();
私人的HashMap<弦乐,产品> listdatachild =新的HashMap<弦乐,产品>();
公共ExpandableListAdapter(上下文的背景下,ArrayList的<产品> FLIST)
{
对于(产品数据:FLIST){
listdatachild.put(data.Name,数据);
} 对于(产品数据:FLIST){
listdataheader.add(data.Name);
} this.context =背景;
} @覆盖
公共对象getChild(INT groupPosition,诠释childPosition){
返回listdatachild.get(this.listdataheader.get(groupPosition);
} @覆盖
公众诠释getChildrenCount(INT groupPosition){
返回listdatachild.size();
}
}I have an expandableListAdapter in
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. I am having the errors for the following methods
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); }
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
andsize
, keep it simple!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(); } }
这篇关于如何读取ExpandaListView的getChild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文