Say I have an Earthquake
class which has a field public final double magnitude;
, and I have a layout similar to this one:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="earthquake" type="com.example.Earthquake"/>
</data>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@{String.format(earthquake.magnitude)}" />
...
</LinearLayout>
</layout>
Note I have to use "@{String.format(earthquake.magnitude)}"
to use this field, else I get this error:
Cannot find the setter for attribute 'android:text' on android.widget.TextView with parameter type double.
Unfortunately, this results in the double being printed at full accuracy. How can I format the double value that is shown?