0

I have a number of preferences that need to be set and I want to guide the user through the flow by popping up the individual preference dialogs (ListPreference, EditTextPreference etc.), one at a time so that I can create a wizard-style UI.

As the user fills in a pref, it closes and the next one opens up.

As far as I know, the user has to click on a preference for the dialog to popup.

Is there any way to do this programmatically?

likejudo
  • 3,396
  • 6
  • 52
  • 107

1 Answers1

1

You can use onItemClick to perform a click on the preference item.

Get the preference position from the preference order.

int position = findPreference("language").getOrder();

language is the preference key.

Then, do onItemClick on the preference item with the position.

getPreferenceScreen().onItemClick(null,null,position,0);
Libin
  • 16,967
  • 7
  • 61
  • 83
  • onItemClick() is a listener? The docs are unclear on how to use it. anyway, how would I popup the first preference? `http://developer.android.com/reference/android/preference/PreferenceScreen.html#onItemClick(android.widget.AdapterView, android.view.View, int, long)` – likejudo Apr 22 '14 at 14:27
  • Do this getPreferenceScreen().onItemClick(null,null,0,0); – Libin Apr 22 '14 at 14:42
  • onItemClick is not a Listener, You can explicitly call this to perform a click on any item – Libin Apr 22 '14 at 14:45
  • That worked! any insight on this from you will be much appreciated... **Issues trying to create a custom dialog preference that gets a time period** http://stackoverflow.com/q/23254405/398348 – likejudo Apr 23 '14 at 20:23