-1

How can i save value as float from EditTextPreference?

I follow this PreferenceActivity: save value as integer But i did not work for me. my preference file is

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory 
    android:title="Taxes"
    android:key="first_category">

    <CheckBoxPreference 
        android:key="include_taxes"
        android:summary="Include or Exclude taxes"
        android:title="Include Taxes" 
        android:defaultValue="true"
    />
<PreferenceScreen 
    android:key="Entering_Taxes"
    android:title="Enter the Values"
    android:dependency="include_taxes"
    android:persistent="false">

        <EditTextPreference
            android:key="ED_tax"
            android:title="E.D Tax" 
            android:summary="Define E.D Tax"
            android:dialogTitle="Set E.D Tax"
            android:dialogMessage="Enter the value" 
            android:defaultValue='7.30'/>

    </PreferenceScreen> 
</PreferenceCategory>   

I have to add all values of taxes.

Community
  • 1
  • 1
Mano2733
  • 13
  • 4

1 Answers1

-2

say you can get string of editTextPreference like this,

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String value = preferences.getString("SomeKey", "");

so convert that string to float like this:

float f = Float.valueOf(value);
Marko Niciforovic
  • 3,561
  • 2
  • 21
  • 28