Android DataBinding 浮动到 TextView [英] Android DataBinding float to TextView

查看:36
本文介绍了Android DataBinding 浮动到 TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绑定:

 @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 或其他值,则我无法删除这些金额.我可以输入文本,但它确实存在.

However on clicking the EditText I am presented with a a text input not the number pad. If I click this EditText again I am then presented with the number pad. If the field has been defaulted to 50.0 or another value I cannot delete these amounts. I can enter text though and it does persist.

有没有其他人遇到过这种行为,第一次点击时出现文本输入而不是数字键盘?EditText 上的双向绑定也按我期望的方式工作.我已经编写了自己的 Binding 和 InverseBinding 适配器,它们的行为方式相同 -> 第一次单击时为 TextInput,然后在第二次单击时使用数字键盘,但您无法删除开始的数字.

Has anyone else come across this behavior with the text input coming up on first click rather than the number pad? Also does the two way binding on EditText work the way I am expecting. I have written my own Binding and InverseBinding adapter and they behave in the same way -> TextInput on first click and then number pad on second click but you cant delete the number that you start with.

推荐答案

试试这个

<EditText
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:inputType="numberDecimal"
            android:text="@={String.valueOf(weightSet.roundInEditAmount)}"/>

这篇关于Android DataBinding 浮动到 TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆