首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >让DependsOn在RoboBinding中工作

让DependsOn在RoboBinding中工作
EN

Stack Overflow用户
提问于 2015-07-06 15:32:41
回答 1查看 59关注 0票数 4

在RoboBinding中有注释DependsOnStateOf。在这样的PresentationModel中使用它时:

代码语言:javascript
复制
@PresentationModel
class GreetingPresentationModel {
    String firstname;
    String lastname;
    //getters and setters for both
    @DependsOnStateOf("firstname")
    public boolean isLastnameInputEnabled() {
        return !TextUtils.isEmpty(firstname);
    }
}

这不管用。下面的绑定将始终为false,并且不会更改。

代码语言:javascript
复制
bind:enabled="{lastnameInputEnabled}"

怎么了?

EN

回答 1

Stack Overflow用户

发布于 2015-07-06 15:32:41

查看RoboBinding AndroidMVVM示例,使用PresentationModelChangeSupport实现HasPresentationModelChangeSupport并使setter调用firePropertyChange是至关重要的

代码语言:javascript
复制
@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");
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31240082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档