How do I format a double using Android view data bindings? -


say have earthquake class has field public final double magnitude;, , have layout similar 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 have use "@{string.format(earthquake.magnitude)}" use field, else error:

cannot find setter attribute 'android:text' on android.widget.textview parameter type double.

unfortunately, results in double being printed @ full accuracy. how can format double value shown?

i haven't yet looked @ binding expression language in m sdk preview, might jumping conclusions, if calls through normal string.format() method, requires pattern. have tried this?

android:text='@{string.format("%.1f", earthquake.magnitude)}' 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -