简体   繁体   中英

Is it possible to list contacts in list preferences in android?

I want to add the contact list to the "list preferences" in android so that the user can select the contact as a preference. But unfortunately I'm unable to find a way to do it. Can anyone help me out with it.

Note: I'm still a noob when it comes to android development, so i wud be a lot thankful if u can explain it in simple terms. :)

Thanks in advance.

Do one thing get all contacts using Content resolver and stored in cursor. After that fetch all contact names using contentresolver.query() method and store all names in a Array of Strings.

Then create dynamic Listpreference using this code :

PreferenceScreen pf = getPreferenceManager().createPreferenceScreen(this);
dialogBasedPrefCat.setTitle("Category Title");
pf.addPreference(dialogBasedPrefCat);

enter code here

ListPreference lf = new ListPreference(this);
        lf.setKey("keyName"); //Refer to get the pref value
        lf.setEntries("Array of values");
        lf.setEntryValues("Array of item value"); // Here you can add Array of String
        lf.setDialogTitle("Dialog Title"); 
        lf.setTitle("Title");
        lf.setSummary("Summary");
        dialogBasedPrefCat.addPreference(lf); Adding under the category

        return pf;

i think it can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM