0
的文本我創建這些方法來定義數據綁定創建於Android和短整型值不同InverseBindingAdapter:EditText上
@BindingAdapter("android:text")
public static void setShortText(TextView view, short value) {
view.setText(String.valueOf(value));
}
@InverseBindingAdapter(attribute = "android:text")
public static Short getShortText(TextView view) {
try {
return Short.parseShort(view.getText().toString());
} catch (NumberFormatException e) {
return null;
}
}
@BindingAdapter("android:text")
public static void setIntText(TextView view, int value) {
view.setText(String.valueOf(value));
}
@InverseBindingAdapter(attribute = "android:text")
public static Integer getIntText(TextView view) {
try {
return Integer.parseInt(view.getText().toString());
} catch (NumberFormatException e) {
return null;
}
}
並結合我的短期和整型變量的觀點。當我建立我的項目時,自動生成的java使用前三種方法,而且它沒有使用第四種方法(getIntText
),問題在這裏。它使用整數字段getShortText
並導致編譯時間casting
錯誤。
我很驚訝,數據綁定正確地檢測到它應該使用setIntText
設置整數值的意見,但它無法識別inverseBinding。
我該如何解決這個問題?
請注意,因爲我想有當空
android:text="@={`` + obj.field}