Question

I'm looking for a way to show a second list in a preference, after a user has selected a choice in a listpreference

For example : the user selects the option "Send sms to" from a list, then a second list appears, and the user can choose a contact.

At the moment, i'm trying to put a onSharedPreferenceChanged method from my preference activity, and show an alert Dialog containing the contacts after a selection, but i think there is another way... But i havent found it yet on the Internet...

Does anyone know how it is possible ?

Thank's

Was it helpful?

Solution

In your PreferenceActivity put a method like below that listens for when that specific key is clicked.

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
        String key) {

    //Make sure the item changed was the list_preference 
    if(key.equals("list_preference")) {
        String value = sharedPreferences.getString(key, "Nothing");

        if(value.equals("Send_sms")) {
            //launch AlertDialog with list or launch new preference 
        }       
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top