PreferenceActivity: save value as integer

前端 未结 5 698
一向
一向 2020-12-12 17:00

Using a simple EditTextPreference in my preferences activity:



        
5条回答
  •  自闭症患者
    2020-12-12 17:49

    I had the same Problem. (I wanted SharedPreference to give me a port number that i stored in a preferences xml file as defaultValue).

    Implementing all the SharedPreferences methods would be much effort, so writing a custom method in the class that instanced the SharedPreferences, as broot suggested would be best i think.

    You can aswell just use the Static method of Integer in the line where you need it:

    int number = Integer.valueOf(settings.getString("myNumberString", "0"));
    

提交回复
热议问题