简体   繁体   中英

Adding an item to listpreference

I have a preference screen containing a preferenceList. i want the user to be able to add new friends to that list.

I have been unable to find any examples of how i can achieve such a thing doing run time.

Does anyone have an example or able to give me an example of how i would achieve this?

Here is my preference:

<PreferenceCategory android:title="Your competetion">
            <PreferenceScreen
        android:key="secondPrefScreen"
        android:summary="click here to see your friends"
        android:title="Friends" >
        <ListPreference
            android:key="friendList"
                />
    </PreferenceScreen>

You can access the ListPreference object at runtime and use the setter and getter methods to update the entries. ListPreference Docs

Assuming you are inside a PreferenceActivity:

   PreferenceScreen root = this.getPreferenceScreen();
   ListPreference list = (ListPreference) root.findPreference("secondPrefScreen");
   // do stuff with list

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