在build.gradle中添加:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
在app。gradle中添加:
dependencies {
implementation 'com.github.zhujiang521:Filter:Tag'
}
private void initView() {
tvFlow = findViewById(R.id.tv_flow);
tvFlow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
flowPopWindow = new FlowPopWindow(MainActivity.this, dictList);
flowPopWindow.showAsDropDown(tvFlow);
flowPopWindow.setOnConfirmClickListener(new FlowPopWindow.OnConfirmClickListener() {
@Override
public void onConfirmClick() {
StringBuilder sb = new StringBuilder();
for (FiltrateBean fb : dictList) {
List cdList = fb.getChildren();
for (int x = 0; x < cdList.size(); x++) {
FiltrateBean.Children children = cdList.get(x);
if (children.isSelected())
sb.append(fb.getTypeName() + ":" + children.getValue() + ";");
}
}
if (!TextUtils.isEmpty(sb.toString()))
Toast.makeText(MainActivity.this, sb.toString(), Toast.LENGTH_LONG).show();
}
});
}
});
}
/**
* 添加筛选框的数据
*/
private void initParam() {
String[] sexs = {"本地", "在线"};
String[] colors = {"新建", "原有", "改造"};
String[] company = {"交流20kv", "交流10kv", "交流5kv"};
FiltrateBean fb1 = new FiltrateBean();
fb1.setTypeName("获取方式");
List childrenList = new ArrayList<>();
for (String sex : sexs) {
FiltrateBean.Children cd = new FiltrateBean.Children();
cd.setValue(sex);
childrenList.add(cd);
}
fb1.setChildren(childrenList);
FiltrateBean fb2 = new FiltrateBean();
fb2.setTypeName("建设类型");
List childrenList2 = new ArrayList<>();
for (String color : colors) {
FiltrateBean.Children cd = new FiltrateBean.Children();
cd.setValue(color);
childrenList2.add(cd);
}
fb2.setChildren(childrenList2);
FiltrateBean fb3 = new FiltrateBean();
fb3.setTypeName("电压等级");
List childrenList3 = new ArrayList<>();
for (String aCompany : company) {
FiltrateBean.Children cd = new FiltrateBean.Children();
cd.setValue(aCompany);
childrenList3.add(cd);
}
fb3.setChildren(childrenList3);
dictList.add(fb1);
dictList.add(fb2);
dictList.add(fb3);
}