Android 更改域中非持久模型字段的适配器内的数据
这是我的模型类,其中,Android 更改域中非持久模型字段的适配器内的数据,android,android-adapter,realm,Android,Android Adapter,Realm,这是我的模型类,其中,isChecked是非持久性的 public class MyModel extends RealmObject { private String name; private String destination; @Ignore private boolean isChecked; public String getName() { return name; } public void se
isChecked
是非持久性的
public class MyModel extends RealmObject {
private String name;
private String destination;
@Ignore
private boolean isChecked;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
}
}
在我的适配器中,当用户选择列表中的项目时,我必须更改isChecked
的值
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.Name.setText(myModels.get(position).getName());
holder.Destination.setVisibility(View.VISIBLE);
holder.Destination.setText(myModels.get(position).getDestination());
updateCheckedState(holder, myModels.get(position), false);
holder.label.setOnClickListener(v -> {
myModels.get(position).setChecked(!myModels.get(position).isChecked());
updateCheckedState(holder, myModels.get(position), true);
});
}
但价值保持不变。当我没有使用
Realm
覆盖onResume()
别忘了
super.onResume()代码>myModels看起来怎么样?如果您使用的是new MyModels()
,则创建的对象将不会由Realm管理。本文档可能会让您了解领域如何管理对象。