Java 让DependsOn在RoboBinding中工作

Java 让DependsOn在RoboBinding中工作,java,android,mvvm,data-binding,robobinding,Java,Android,Mvvm,Data Binding,Robobinding,在RoboBinding中有注释DependsOnStateOf。 在这样的PresentationModel中使用它时: @PresentationModel class GreetingPresentationModel { String firstname; String lastname; //getters and setters for both @DependsOnStateOf("firstname") public boolean isL

在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和IDMVVM示例,使用
PresentationModelChangeSupport
实现
HasPresentationModelChangeSupport
并让设置者调用
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");
    }
}

您可以添加RoboBinding aspectJ支持,以避免手动编写firePropertyChange代码。它将在firePropertyChange代码中为您自动编织。@Cheng有什么方法可以从ItemPresentationModel中执行此操作或firePropertyChange()吗?@Cheng顺便说一句,非常感谢您为RoboBinding所做的工作:)@beerBear您可以在ItemPresentationModel中完成PresentationModel所能做的一切。ItemPresentationModel是PresentationModel的概念扩展。