views:

39

answers:

1

Hello,

I've created a ListPreference in PreferenceActivity and it works good:

  • user clicks on the Preference item
  • a list dialog opens (retrieves listItems and their values from array.xml)
  • if the user selects one of the list items it saves his selection (which I can later retrieve).

My question is: how can I preform a method the second he presses one of the list items (according to the user selection)?

Appreciate any help!

+1  A: 

You can register a OnPreferenceChangeListener for any given preference by calling its setOnPreferenceChangeListener() method.

Aaron C
Tried what you said:Preference sorted = (Preference) findPreference("sortPref"); sorted.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { testing(); return true; } });and it allows me to know if the Preference Item is clicked and not the listItem in the newly opened dialog...Any ideas?
liorry
sortPref is the ListPreference key.The dialog it opens is generated from arrays.xml which contains titles and values.
liorry
setOnPreferenceClickListener() should trigger when the user clicks the preference. setOnPreferenceChangeListener() should trigger when they select a preference from the dialog.
Aaron C
Works! Many thanks!
liorry