checkbox - 使用复选框在 recyclerview 上搜索。在搜索我的搜索复选框后选中,但默认选中该位置的复选框的原始列表
解决方案
您可以在此处使用所选项目方法。在您的模型类中使用项目选择器布尔值,如下所示:
public class ItemModel {
boolean isSelcted;
public boolean isSelcted() {
return isSelcted;
}
public void setSelcted(boolean selcted) {
isSelcted = selcted;
}
}
现在,当用户选择任何复选框时,将所选项目的布尔值设置为 true,然后像这样刷新适配器。
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
for (ItemModel model : itemList) {
model.setSelcted(false);
}
model.setSelcted(true);
notifyDataSetChanged();
}
}
});
现在在您的搜索框中搜索任何内容。如果您在 searchList 中传递相同的列表,那么它将按预期显示选中和未选中的复选框。
推荐阅读
- php - 如何在显示 mysql 表的函数中包含分页?
- c# - 如何使用 fo-DICOM 删除或更新私有标签?
- r - ts 命令在 R 上给了我错误的数据
- excel - 在 VBA 中:我可以使用查找函数来定义一个变量,然后用于定义一个范围吗?
- mysql - 组和子查询问题
- sql - PostgreSQL - 如何找到与它匹配的记录的行,其值高于给定值?
- java - 从浏览器边框验证按钮填充
- java - 如何在 Android Studio 的单独活动中从单选按钮调用信息
- python - 如何绘制一个 DataFrame 列与另一列,每个列在其自己的子图中由第三列?
- python - 如何使用 init 参数为处理程序设置龙卷风路由?