Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带布尔数组的嵌套RecyclerView?_Java_Android_Android Recyclerview - Fatal编程技术网

Java 带布尔数组的嵌套RecyclerView?

Java 带布尔数组的嵌套RecyclerView?,java,android,android-recyclerview,Java,Android,Android Recyclerview,我正在开发一个应用程序,该应用程序具有连接到设备的动态开关数。这是我的模型课: public class SwitchModel { private String product; private String deviceId; private ArrayList<Boolean> switchPool; public SwitchModel(String product, String deviceId, ArrayList<Boolean> switchPool

我正在开发一个应用程序,该应用程序具有连接到设备的动态开关数。这是我的模型课:

public class SwitchModel {

private String product;
private String deviceId;
private ArrayList<Boolean> switchPool;

public SwitchModel(String product, String deviceId, ArrayList<Boolean> switchPool) {
    this.product = product;
    this.deviceId = deviceId;
    this.switchPool = switchPool;
}
下面是我的子适配器的代码:

public class ChildAdapter extends RecyclerView.Adapter<ChildAdapter.ViewHolder> {

private ArrayList<Boolean> switches;

public ChildAdapter(ArrayList<Boolean> switches) {
    this.switches = switches;
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

    Boolean model = switches.get(position);

    holder.switchButton.setChecked(model);

    holder.switchButton.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(SwitchButton view, boolean isChecked) {
            Log.i("myResponse", "onCheckedChanged: " + view.isChecked());
            return;
        }
    });
}
公共类ChildAdapter扩展了RecyclerView.Adapter{ 专用ArrayList交换机; 公共子适配器(ArrayList开关){ 这个。开关=开关; } @凌驾 public void onBindViewHolder(@NonNull ViewHolder,int位置){ 布尔模型=开关.get(位置); 支架。开关按钮。设置检查(型号); holder.switchButton.setOnCheckedChangeListener(新的switchButton.OnCheckedChangeListener(){ @凌驾 检查更改后的公共无效(开关按钮视图,布尔值已检查){ Log.i(“myResponse”,“onCheckedChanged:+view.isChecked()); 返回; } }); }
RecyclerView
正确设置了开关的选中值。但我的问题是,正如您在我的子视图中所看到的,我为数组列表的每个索引绑定了一个布尔值,但是当我调用检查更改侦听器时,它不会返回产品的确切开关号。如果有人能帮我解决这个问题,那就太好了。

I w我们可能会尝试利用谷歌的优势

本质上,您可以为N个适配器提供N个数据并单独更新/处理它们。我从来没有尝试过自己这样做,我不想让这听起来像是一件容易的事情,但它似乎“可能适合您描述的用例”

有人这么说,也许这会在你试图让它工作之前,为你指明正确的方向

public class ChildAdapter extends RecyclerView.Adapter<ChildAdapter.ViewHolder> {

private ArrayList<Boolean> switches;

public ChildAdapter(ArrayList<Boolean> switches) {
    this.switches = switches;
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

    Boolean model = switches.get(position);

    holder.switchButton.setChecked(model);

    holder.switchButton.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(SwitchButton view, boolean isChecked) {
            Log.i("myResponse", "onCheckedChanged: " + view.isChecked());
            return;
        }
    });
}