使用带有实时数据的房间......我无法弄清楚的一点是:
object1.isSelected == true;
object2.isSelected == false;
object3.isSelected == false;
如果我设置' isSelected'如果在object3上为true,我希望它在对象1中变为false。
有没有办法在不观察两个对象,进行切换,然后更新两个对象的情况下执行此操作?
答案 0 :(得分:0)
您可以通过创建一个类来完成。
public class OneBoolean{
private Object[] objects;
public OneBoolean(Object objects..){
this.objects = objects;
}
private void setSelected(int index){
// This is first approach. You can store the previous selected index and just change it false, and change this true
for(int i=0 ; i<objects.length() ; i++){
objects[i].isSelected = (i==index);
}
}
}