【发布时间】:2017-06-27 11:17:06
【问题描述】:
我对 Android 绑定库有疑问。当我使用属性更改“_all”时,一切正常,但是当我指定字段时,它不起作用。 我的问题是为什么? :)
public class Person extends BaseObservable{
private String name;
@Bindable
public String getName(){
return this.name;
}
//IT WORKS
public void setName(String name){
this.name = name;
notifyPropertyChanged(BR._all); //<- difference
}
//IT DONT WORK
public void setSurname(String name){
this.name = name;
notifyPropertyChanged(BR.name); //<- difference
}
还有我的 xml 文件:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="person"
type="com.myapp.Person" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{person.getName()}" />
</LinearLayout>
</layout>
【问题讨论】:
标签: android android-layout data-binding android-databinding