Create two-way binding with Android Data Binding

前端 未结 6 1337
情深已故
情深已故 2020-12-08 06:33

I have implemented the new Android data-binding, and after implementing realised that it does not support two-way binding. I have tried to solve this manually but I am strug

6条回答
  •  没有蜡笔的小新
    2020-12-08 06:50

    There is a simpler solution. Just avoid updating field if it hadn't really changed.

    @Bindable
    public String getFirstName() {
        return firstName;
    }
    
    public void setFirstName(String firstName) {
         if(this.firstName.equals(firstName))
            return;
    
         this.firstName = firstName;
         notifyPropertyChanged(BR.firstName);
    }
    

提交回复
热议问题