8
データバインディングを使用しようとしています。文字列の属性を持つオブジェクトを使用すると正しく動作しますが、この場合はintを使用しても動作しません。
public class User extends BaseObservable{
public int age;
......
public User() {}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
...
}
はここ
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.bindingview.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{user.age}"/>
</LinearLayout>
</layout>
問題はTextViewにはintで、年齢のテキストを持つことができないということである私のレイアウトです: 私は、オブジェクトのユーザーを持っています。 intからage属性の文字列に変更するとうまくいきました。 この問題を回避するにはどうすればよいですか?
は、あなたは私の命を救っ – lovefish
〜ありがとうございました。 – itmammoth