4

在 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}"

怎么了?

4

1 回答 1

0

查看 RoboBinding AndroidMVVM 示例,实现HasPresentationModelChangeSupportusingPresentationModelChangeSupport和 make setter call至关重要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");
    }
}
于 2015-07-06T07:32:41.053 回答