一.Adapter的使用
和普通的适配器不同,如果你要实现多级目录,Adapter必须继承BaseMultiItemQuickAdapter而不是BaseQuickAdapter,如下图:
MultiItemEntity指不同类型的Bean类
同时对应着不同的布局(Layout)
二.Bean类的设置
多级联动的Bean类必须实现MultiItemEntity接口
如下图:
getItemType()返回的值就是上面在Adapter对应类型的编号
2.1继承规则:
目录按如下格式AbstractExpandableItem<Bean>依次继承它的下级目录,比如一级目录继承二级,二级目录继承三级,最低级的目录不用继承直接实现MultiItemEntity接口即可。
三.数据设置
private ArrayList<MultiItemEntity> generateData() {
int lv0Count = 9;
int lv1Count = 3;
int personCount = 5;
String[] nameList = {"Bob", "Andy", "Lily", "Brown", "Bruce"};
Random random = new Random();
ArrayList<MultiItemEntity> res = new ArrayList<>();
for (int i = 0; i < lv0Count; i++) {
Level0Item lv0 = new Level0Item("This is " + i + "th item in Level 0", "subtitle of " + i);
for (int j = 0; j < lv1Count; j++) {
Level1Item lv1 = new Level1Item("Level 1 item: " + j, "(no animation)");
for (int k = 0; k < personCount; k++) {
lv1.addSubItem(new Person(nameList[k], random.nextInt(40)));
}
lv0.addSubItem(lv1);
}
res.add(lv0);
}
return res;
}
四.父级动态添加子级数据
监听子控件按钮,并根据情况设置数据