Two-way binding cannot resolve a setter for java.lang.String property

不羁岁月 提交于 2019-12-05 08:58:06

If you are working with kotlin , make sure data class field used for two way binding is declared as var. If it is val unable to support two way binding

This bug is ugly as hell and properly a bug in the data binding API. The solution is to generate a setter and a getter. I came up fast with the idea to create a setter, but not to create a getter.

Here is now my simplified model:

public class Address {
    public String street;

    public void setStreet(String street) {
        this.street = street;
    }

    public String getStreet() {
        return street;
    }
}

As you may note the getter and setter are useless, but required for two way binding.

If you think that this is a bug of the API please star my bug report: Two-way binding required setters AND ALSO getters

According to databinding offical repo https://android.googlesource.com/platform/frameworks/data-binding/ commit message, this bug has been fixed at Android Studio 2.2 preview 3.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!