Question

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>
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top