效果图
choice.gif
简介
如上图展示的内容,筛选条件的功能很常见,一般情况如果条件很多,那么布局文件就会写的很复杂,这篇文章可以提供一个简洁的方案,布局文件只用一个RecyclerView就可以了。当然,处理逻辑可能要少费点功夫,不过这些逻辑可以复用,如果有多个地方用到就省很多事了。
代码分析
先看看Bean类的处理:
数据中有几个必须要添加的属性
type:用于区分是标题item还是内容item,标题item也可以分很多类。
choice:标记item是否选中
multiChoice:这一类型标签是不是多选
allChoice:标签item是不是全选按钮(根据需求调整)
public class GridItemBean {
/**
* type:
* 标题item 自定义
* 内容item 默认为0
*/
private int type;
/**
* 标题(标题item)
*/
private String title;
private String id;
private String name;
/**
* 内容item 是否选择(内容item)
*/
private boolean choice;
/**
* 是否是多选(标题item)
*/
private boolean multiChoice;
/**
* 是否是全选按钮(内容item)
*/
private boolean allChoice;
public GridItemBean(int type, String title) {
this.type = type;
this.title = title;
}
public GridItemBean(int type, String title, boolean multiChoice) {
this.type = type;
this.title = title;
this.multiChoice = multiChoice;
}
public GridItemBean(String id, String name) {
this.id = id;
this.name = name;
}
public GridItemBean(String id, String name, boolean allChoice) {
this.id = id;
this.name = name;
this.allChoice = allChoice;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name =