Data Binding常见问题

  1. Data Binding相关
    Cannot find the setter for attribute “xxx”
    检查属性的类型与BindingAdapter参数的类型是否一致,参考:https://stackoverflow.com/questions/45140008/cannot-find-the-setter-for-attribute-attribute-with-parameter-type-type-on

Gradle Console:
**/ data binding error ****msg:Cannot find the setter for attribute ‘app:updateDetailContentWidth’ with parameter type boolean on android.widget.TextView.
file:D:\HMI-common\NavHome\Apps\Rainier\HMI\src\main\res\layout\sloped_entity_detail.xml
loc:721:58 - 721:89
loc:722:68 - 722:99
*\ data binding error *

  1. Bindable相关

@Bindable
public int getnextFocusId(int viewId) {
// implementations
}

Gradle Console:
@Bindable associated with method must follow JavaBeans convention getNextFocusId(int)
解释:https://medium.com/@salismt/android-vector-and-databinding-marriage-part-1-bb0ac0a399ab

Wait, why it’s only viewModel.text instead of viewModel.getText? Actually, android DataBinding follows JavaBean convention, so it will ignore suffix isfor boolean, and get for other types.

getter的参数列表必须为空!!!
JavaBenas convention:
https://en.wikipedia.org/wiki/JavaBeans
http://csc.columbusstate.edu/woolbright/java/beans.html

你可能感兴趣的:(Android开发)