I am using Binding adapter to prevent constant text update of edittexts for 2 way binding.
@BindingAdapter("binding")
public static void bindEditText(EditText editText, final String str) {
if ((!editText.getText().toString().equals(str)) && !editText.getText().equals("")) {
editText.setText(str);
}
}
It works fine with edit text with integer default text. But when it comes to edit text with float default text. Ex: 70.0, when I key in the first digit, the edit text refreshes and became Ex: 8.0. The cursor then move to left and all the following digits will be added to the front. Ex: 198.0
Tried this, but doesn't work.
@BindingAdapter("binding")
public static void bindEditText(EditText editText, final String str) {
if ((!(editText.getText().toString()+".0").equals(str)) && !editText.getText().equals("")) {
editText.setText(str);
}
}
Any solution?