Fun with Edit Text Preference
It has been a challenge understanding some of the Preference
concepts that are being taught in this exercise. For example, we use the PreferenceScreen
in our XML file. However, when I look up the documentation trying to understand exactly what it does, it says
Represents a top-level Preference that is the root of a Preference hierarchy. A PreferenceActivity points to an instance of this class to show the preferences
The documentation doesn’t say much else and I am not able to see what the preference hierarchy looks like.
In this exercise, we made an editable text box using EditTextPreference
. It will display an edit box to the user and whatever value they enter will be stored in SharedPreference
.
Edit Text Preference Screenshot
I found a nifty diagram which is close to ones I made in the past. It shows how an activity can inject a fragment into an activity to create a more
Preference Fragment Workflow Diagram
The onSharedPreferenceChanged
is a listener that will detect changes being made by the user. It will receive and update the activity with those settings.
Shared Preferences API
There are a lot of moving parts. I do see the value of having the Preferences
API, however, it can be a bit of a black box. There is not a lot of documentation explaining how the various parts work. Perhaps I am just inexperienced and will figure it out someday.