I have this adapters in a Binding Utils class:
@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);
}`
And this is part of one of my xml files:
<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}"/>`
The thing is that in Android Studio 2.2.3 version is working great. When I updated to Android Studio 2.3 this stopped working and Gradle shows multiple errors. I have changed the attribute of the Binding adapters and Inverse binding adapters from "android:text" to "text" but it's not working. Something similar happened to another user in this question: Data Binding broke after upgrade to Gradle 2.3 but the difference is that I'm using "android:text" for the binding so the answer given by George Mount is no working for me. Anybody has any ideas? I'm really frustrated with this because I can't update Android Studio because of this problem.