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的使用方法一样。