Set PreferenceScreen type as “Select Contact”

2020-07-23 05:49发布

问题:

I have a PreferenceActivity with a few EditText and CheckBox Preferences. I would like to add a preference of Contact so that when the button was pressed it would allow the selction of a Contact's number

Is that possible using the PreferenceActivity functionality?

TIA

Pat Long

回答1:

AFAIK I know there is no direct Preference object to do this. But you can create your own, if you extend DialogPreference or Preference

Probably you have to just fire a contact picker, and listen for the results.

I would be too interested, so I would love to see the code shared.



回答2:

Check out what this person did: http://yenliangl.blogspot.com/2010/01/provide-phonepreference-from.html. It seems a bit hacky, but by subclassing RingtonePreference you can override the RingtonePreference bits and get the benefit of the package-protected internals that RingtonePreference has access to.

Combined with the info on the Contacts API (http://developer.android.com/resources/articles/contacts.html), things seem to work. Maybe someone else will pipe up with a better way.