0

I can't seem to understand why I keep getting the "default" string show up when I grab input from the EditTextPreference.

<EditTextPreference
       android:title="@string/settings_title_signature"
       android:summary="@string/settings_enter_signature"
       android:singleLine="true"
       android:key="edit_signature_key"
/>

I never seem to get what the textfield has using Sharedpreferences. It just defaults to the "default", and not what should be in the key.

SharedPreferences myPreference = PreferenceManager.getDefaultSharedPreferences(this);
String sig = myPreference.getString("edit_signature_key", "default");
  • go thought this even its bit old-> https://androidpartaker.wordpress.com/tag/edittext-preference-summary/ – Charuක Dec 09 '16 at 02:20

1 Answers1

0

Make sure you are using the EditTextPreference inside of a Preference Screen or Preference Fragment. Sounds like you are just using a standalone EditTextPreference.

If you are using it in the right container, please update your post with all of your code and I will be able to help.

(had to put this as an answer instead of a comment because I don't have enough rep)

Nick Friskel
  • 2,369
  • 2
  • 20
  • 33
  • Thanks for your suggestions mate. Though I'm modifying part of a large repository on git-hub, so putting the whole code here may be a little too much. I did re-write shared preferences to this: SharedPreferences myPreference = this.getSharedPreferences("edit_signature_key", Context.MODE_PRIVATE); But still stuck with the same problem. – Display Name Dec 09 '16 at 02:47
  • No problem my dude. If you are using a PreferenceScreen or PreferenceFragment then it will write to you default preferences, so that is not where the problem is. Only thing I can think of is if your update methods are not setup correctly, like in your onCreatePreferences method where the preferences are set up, you should have onSharedPreferenceChanged(sharedPrefs, getString(R.string.editKey)); and then in your Strings have edit_signature_key – Nick Friskel Dec 09 '16 at 02:54