views:

42

answers:

3

I am using preference concept (listpreference) in my application. I want to do something when i choose particular option from list So plese tell me how is it possible?

A: 

Take a look at that post :

To read these preferences from code, we should create a getPrefs() method, which we can call in the onStart() method. When we call it in the onStart() method instead of onCreate(), we can be sure that the preferences load when we have set them and returned to our main activity,

private void getPrefs() {
                // Get the xml/preferences.xml preferences
                SharedPreferences prefs = PreferenceManager
                                .getDefaultSharedPreferences(getBaseContext());
                CheckboxPreference = prefs.getBoolean("checkboxPref", true);
                ListPreference = prefs.getString("listPref", "nr1");
                editTextPreference = prefs.getString("editTextPref",
                                "Nothing has been entered");
                ringtonePreference = prefs.getString("ringtonePref",
                                "DEFAULT_RINGTONE_URI");
                secondEditTextPreference = prefs.getString("SecondEditTextPref",
                                "Nothing has been entered");
                // Get the custom preference
                SharedPreferences mySharedPreferences = getSharedPreferences(
                                "myCustomSharedPrefs", Activity.MODE_PRIVATE);
                customPref = mySharedPreferences.getString("myCusomPref", "");
        }
mgpyone
Thanks for your reply!Actually My problem is different.My application has two tabs. In second tab preference screen appears out of which one is listpreference. When I choose any option from list for changing background screen then i did not get immediate effect in the preference screen with changed background image and when I go to first tab then i can look changed screen background and now when i come in second tab(preference screen) then i got effect I want immediate response in preference screen with changed background image. Hope you will get what i need. pls suggest!
shobhit
A: 

make your preference activity implement onPreferenceChangeListener and then you need to find the preference by its key in onCreate and register the listener.

schwiz
thanks for help!
shobhit