美文网首页
二级列表 ExpandableListView

二级列表 ExpandableListView

作者: 安多人 | 来源:发表于2018-03-26 20:23 被阅读0次

1、利用数组实现二级列表
String mgroup={"西游记","三国演义","水浒","红楼梦"};
String mChild[][] ={ {"猪八戒","孙悟空","唐僧"},{"刘","关","张","曹"},{"宋江","林冲","武松","李逵"},{"贾宝玉","林黛玉","薛宝钗","王熙凤"}};
ExpandableListView exListView = findViewById(R.id.ExpandableListView);
exListView.setAdapter(MyAdapter);

写我们自己的Adapter,继承自BaseExpandableAdapter实现10个函数,将设备上下文Context mContext和两个数组作为Adapter的三个变量,mgroup.length为分组个数。mChild[groupposition].length为指定分组数据条数。
public View getGroupView()//获取组视图
public View getChildView()//获取组子项视图
这里面有两个视图,所以我们要写两个Item,就是两个XML文件,在获取组视图和获取子视图时,使用方法和ListView的使用方法一样。

相关文章

网友评论

      本文标题:二级列表 ExpandableListView

      本文链接:https://www.haomeiwen.com/subject/sdalcftx.html