Unable to bind double with data binding to Android

I have a class that extends BaseObservable, this class contains a double value

That's an example:

public class BindedValue extends BaseObservable {

public double value;


public TextWatcher setValue = new TextWatcherAdapter(){

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

Then I got 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}"/>

When I try to run or build the application, I get this error:

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

However, when I change the type to int, the application builds without problems.

Is there a way to tie a double?

+7
source share
3 answers

However, when I change the type to int, application assemblies now exit.

Yes, but it will work at runtime. setText(int)expects a string resource identifier, not an arbitrary one int.

Is there a way to bind a double?

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

android:text="@{String.ValueOf(BindedValue.value)}"
+1

:

android:text='@={""+item.value}'

-, String :

public void setValue(String value) {
    this.setValue(Double.valueOf(value));
}
0
source

All Articles