Combo preference in Android
My desired custom preference looks very much like the out-of-box EditTextPreference, only that it behaves like a "split button" which combines two Preferences: if user clicks on the text on the left, the edit text dialog pops up; which allows user to set the "label" for the preference; if user clicks on the button on the right, another window开发者_开发百科 pops up that allows user to set the "date" for the preference.
I guess I could extend EditTextPreference but I am not sure how I can maintain two separate keys for a single preference control (or "widget" in Android's term). Or is it possible to "mix up" two Preferences without subclassing?
Really you do not have to use the built in preference widgets to manage your preferences; for example, in my application, i use a PreferenceScreen to bring up a multiple selection dialog with a custom listview/adapter. If you wish to handle your own key/value store, you could bind to the preference with findPreference(), set the value in the PreferenceActivity's onCreate() and persist the value in the activity's onPause(). Examining the key / value preference store can be done via getSharedPreferences(file,MODE.PRIVATE) and an associated getter method. To edit them, take the SharedPreferences object that's returned and call edit() / commit() on it once changes have been made.
Does this answer you question?
精彩评论