我正在尝试绑定(bind):
@Bindable
public float getRoundInEditAmount()
{
return roundInEdit.getAmount();
}
@Bindable
public void setRoundInEditAmount(float amount)
{
roundInEdit.setAmount(amount);
notifyPropertyChanged(BR.roundInEditAmount);
}
到
<EditText
android:layout_width="100dp"
android:layout_height="50dp"
android:inputType="numberDecimal"
android:text="@={`` + weightSet.roundInEditAmount}"
></EditText>
但是,在单击 EditText 时,我看到的是文本输入而不是数字键盘。如果我再次单击此 EditText,则会看到数字键盘。如果该字段默认为 50.0 或其他值,我无法删除这些金额。我可以输入文本,但它确实存在。
有没有其他人遇到过第一次点击时出现文本输入而不是数字键盘的这种行为? EditText 上的两种方式绑定(bind)是否也按照我期望的方式工作。我已经编写了自己的 Binding 和 InverseBinding 适配器,它们的行为方式相同 -> 第一次单击时输入 TextInput,第二次单击时输入数字键盘,但您无法删除开头的数字。
最佳答案
这样试试
<EditText
android:layout_width="100dp"
android:layout_height="50dp"
android:inputType="numberDecimal"
android:text="@={String.valueOf(weightSet.roundInEditAmount)}"/>
关于Android DataBinding float 到 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41154446/