[英]RoboBinding: No such property exception on firePropertyChange()
[英]Making DependsOn work in RoboBinding
在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}"
怎么了?
查看RoboBinding AndroidMVVM示例,使用PresentationModelChangeSupport
實現HasPresentationModelChangeSupport
並使setter調用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");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.