2

How to get double value from declare-styleable?

attributes.xml

<declare-styleable name="MeterView">
    <attr name="volume" format="double"/> // Can't resolved format
</declare-styleable>

Assign double value to meterView

<com.test.example.MeterView
    android:id="@+id/meter1"
    android:layout_width="295dp"
    android:layout_height="150dp"
    app:volume="123456789.01"/>

Calling attributes.xml

Double volume = a.getDouble(R.styleable.MeterView_volume); // Can't resolved getDouble
Ihdina
  • 950
  • 6
  • 21

1 Answers1

3

use float instead of double in your attributes.xml file. double is not allowed.

<declare-styleable name="MeterView">
        <attr name="volume" format="float"/> 
</declare-styleable>

a.getFloat(R.styleable.MeterView_volume);

or use string and convert String to double in runtime.

<declare-styleable name="MeterView">
            <attr name="volume" format="string"/> 
 </declare-styleable>

double d= Double.parseDouble(a.getString(R.styleable.MeterView_volume));
faraz khonsari
  • 1,924
  • 1
  • 19
  • 27