开发者

Display the text back to TextPref

Need to display back the text input provided in Text Preference

    PreferenceCategory generalPrefCat = new PreferenceCategory(this);
    generalPrefCat.setTitle("General Settings");
    root.addPreference(generalPrefCat);

    // Your Name preference
    EditTextPreference namePref = new EditTextPreference(this);
    namePref.setDialogTitle("Your Name");
    namePref.setKey("yourname_preference");
    namePref.setTitle("Your Name");        
    generalPrefCat.addPreference(namePref);
    

Need to display the name entered as summary.namePref.setsummary("Santosh"). First time if its not entered nothing should be displayed.

   SharedPreferences myPreference=PreferenceManager.getDefaultSharedPreferences(this);
   na开发者_如何学运维mePref.setSummary(myPreference.getString("yourname_preference", "")));

How to I get the input string and display it back?


I'm not sure what you're after but I'll give it a shot. If you wan't to get a specific string from settings.getString if there is no saved string under that key, you can just add that string as the second parameter in the method. Like this:

mySettings.getString("user_string", "this_is_the_default_string");

If this isn't what you're looking for, please try to make your question clearer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜