Can't put double SharedPreferences

后端 未结 5 1235
孤城傲影
孤城傲影 2020-11-30 17:56

Getting error, the method put double is undefined for this type of sharedPreferences editor.Eclipse is given one quick fix add cast to editor, but when i do that its still g

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 18:24

    Check this gist https://gist.github.com/john1jan/b8cb536ca51a0b2aa1da4e81566869c4

    I have created a Preference Utils class that will handle all the cases.

    Its Easy to Use

    Storing into preference

    PrefUtils.saveToPrefs(getActivity(), PrefKeys.USER_INCOME, income);
    

    Getting from preference

    Double income = (Double) PrefUtils.getFromPrefs(getActivity(), PrefKeys.USER_INCOME, new Double(10));
    

提交回复
热议问题