在RoboBinding中有注释DependsOnStateOf
。
在这样的PresentationModel中使用它时:
@PresentationModel
class GreetingPresentationModel {
String firstname;
String lastname;
//getters and setters for both
@DependsOnStateOf("firstname")
public boolean isLastnameInputEnabled() {
return !TextUtils.isEmpty(firstname);
}
}
这不起作用。以下绑定始终为false且不会更改。
bind:enabled="{lastnameInputEnabled}"
怎么了?
答案 0 :(得分:0)
查看RoboBinding AndroidMVVM示例,使用HasPresentationModelChangeSupport
实现PresentationModelChangeSupport
并使设置者调用firePropertyChange
至关重要:
@PresentationModel
public class GreetingPresentationModel implements HasPresentationModelChangeSupport {
PresentationModelChangeSupport changeSupport;
@Override
public PresentationModelChangeSupport getPresentationModelChangeSupport() {
return changeSupport;
}
public GreetingPresentationModel() {
changeSupport = new PresentationModelChangeSupport(this);
}
// Rest of the code here
// Then change each setter, e.g.
public void setFirstname(String firstname) {
this.firstname = firstname;
changeSupport.firePropertyChange("firstname");
}
}