Binding Utils クラスにこのアダプターがあります。
@BindingAdapter("text")
public static void bindDoubleInText(AppCompatEditText tv, Double
value)
{
if (tv.getText() == null) return;
// Get the actual EditText value
String edittextValue = tv.getText().toString();
if (edittextValue.isEmpty())
{
if (value != null) tv.setText(Double.toString(value));
}
else
{
if (value != null &&
Double.parseDouble(tv.getText().toString()) != value)
tv.setText(Double.toString(value));
}
}
@InverseBindingAdapter(attribute = "android:text")
public static Double getDoubleFromBinding(TextView view)
{
String string = view.getText().toString();
return string.isEmpty() ? null : Double.parseDouble(string);
}
@BindingAdapter("text")
public static void bindIntegerInText(AppCompatEditText
appCompatEditText, Integer value)
{
CharSequence charSequence = appCompatEditText.getText();
if (charSequence == null || value == null) return;
// Get the actual EditText value
String edittextValue = charSequence.toString();
if (edittextValue.isEmpty() || Integer.parseInt(edittextValue) !=
value)
appCompatEditText.setText(Integer.toString(value));
}
@InverseBindingAdapter(attribute = "android:text")
public static Integer getIntegerFromBinding(TextView view)
{
String string = view.getText().toString();
return string.isEmpty() ? null : Integer.parseInt(string);
}`
そして、これは私のxmlファイルの一部です:
<android.support.v7.widget.AppCompatEditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:gravity="center_horizontal"
android:hint="dosis"
android:inputType="numberDecimal"
android:minEms="5"
android:text="@={workOrderFertilizer.dose}"/>`
問題は、Android Studio 2.2.3 バージョンでうまく機能していることです。Android Studio 2.3 に更新すると、これが機能しなくなり、Gradle に複数のエラーが表示されます。バインディング アダプタとインバース バインディング アダプタの属性を「android:text」から「text」に変更しましたが、機能しません。この質問で別のユーザーに同様のことが起こりました.Gradle 2.3へのアップグレード後にデータバインディングが壊れましたが、バインディングに「android:text」を使用しているため、George Mountからの回答は役に立たないという違いがあります。誰にもアイデアはありますか?この問題で Android Studio を更新できず、本当にイライラしています。