java - 无法使用 Android 数据绑定(bind)进行双重绑定(bind)

标签 java android android-databinding

我有一个扩展 BaseObservable 的类,这个类包含 double 值

这是一个例子:

public class BindedValue extends BaseObservable {

public double value;


public TextWatcher setValue = new TextWatcherAdapter(){

    @Override
    public void afterTextChanged(Editable s) {
        value = Double.parseDouble(s.toString());
    }
  };
}

然后我得到了xml

<data class="net.example.util.Value">

            <variable
        name="BindedValue"
        type="net.makereal.makerealmaquette.domain.BindedValue"/>

    <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:hint="Value"
                android:addTextChangedListener="@{BindedValue.setValue}"
                android:inputType="numberDecimal"
                android:text="@{BindedValue.value}"/>

当我尝试运行或构建应用程序时出现此错误:

Cannot find the setter for attribute 'android:text' with parameter type double on android.widget.EditText.

但是,当我将类型更改为 int 时,应用程序构建没有问题。

有没有办法绑定(bind)一个double?

最佳答案

However when I change the type to int the app builds with now issue.

是的,但它会在运行时失败。 setText(int) 需要一个字符串资源 ID,而不是任意的 int

Is there way to bind double?

android:text="@{Double.toString(BindedValue.value)}"

关于java - 无法使用 Android 数据绑定(bind)进行双重绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36068556/

相关文章:

android - Google Sign-In for Android 中的问题

android - 在布局绑定(bind)中使用属性资源 (?attr/)?

java - Camel 路线无法生成随机 UUID

java - BigIP - Tomcat 8 连接在从 tomcat 6 升级时被拒绝

java - <jsp :scriptlet> and <% %> 之间有什么区别吗

java - 无法调用 findByEmail 因为 "this.userRepository"是空错误

android - 在我的应用程序中即时上传和 Google+ 图片

android - 使用 AndroidAnnotations 的 ClassNotFoundException

android - 为什么我得到 java.lang.NoSuchFieldError : No static field xxxx of type I in class Lpl/myapp/mobile/main/BR; or its superclasses?

android - Picasso 绑定(bind)适配器 'a connection was leaked' 消息