我有清单显示一些东西,每个东西都有一些标签。 我希望通过单击所有标签来过滤东西,并通过取消选择某些标签来更改过滤器。
下面的代码显示了为此编写的实现方法。但是只是过滤器列表买一个标签!如何过滤所有选择的标签?
private OrderedRealmCollection<StuffPOJO> list;
@Override
public void onFiltersSelected(ArrayList<TagPojo> filters) {
}
@Override
public void onNothingSelected() {
UpdateStuffList(list.where().findAllAsync());
}
@Override
public void onFilterSelected(TagPojo item) {
///just filter list buy last tag selected !!!
/// how can filter all tag selected?
UpdateStuffList(list.where()
.equalTo("tagList.id", item.getId())
.findAllAsync());
}
@Override
public void onFilterDeselected(TagPojo item) {
}
@Override
public void UpdateTagList(OrderedRealmCollection<TagPojo> list) {
tagAdapter = new Adapter(list);
}
@Override
public void UpdateStuffList(OrderedRealmCollection<StuffPOJO> list) {
this.list = list;
stuffAdapter.updateData(this.list);
}
答案 0 :(得分:2)
您需要将所有过滤器存储在某处:
private List<TagPojo> filters = new ArrayList<>();
@Override
public void onFilterSelected(TagPojo item) {
filters.add(item);
String[] filterIds = filters.stream().map(f -> f.getId()).toArray(size -> new String[size]);
UpdateStuffList(list.where()
.in("tagList.id", filterIds )
.findAllAsync());
}
@Override
public void onFilterDeselected(TagPojo item) {
// need to have a proper TagPojo.equals() for this
filters.remove(item);
}