10

I want to open some preferences (which are made by extending DialogPreference) on first app startup. Also, these preferences are used as usual preferences.

Is there a way of accomplishing this?

EDIT:

I have my custom preference, made like this:

public class CitySelectPreference extends DialogPreference  {
// Some code here
}

And as the solution I want it to be shown from the code, without the need of user getting to preference screen.

rds
  • 26,253
  • 19
  • 107
  • 134
Prizoff
  • 4,486
  • 4
  • 41
  • 69
  • what version are you compiling against because depending on that there are a few ways – tyczj Jun 21 '12 at 16:55
  • I'm targeting android 2.2... Also, found some answer here: http://stackoverflow.com/a/4869034/1048087 – Prizoff Jun 21 '12 at 17:03
  • i may be misunderstanding your question, but what is wrong with displaying the dialog preference in the oncreate method of the activity? – hmdavis Jun 21 '12 at 17:05
  • how can I do this? I have no access to the CitySelectPreference object from arbitrary code... – Prizoff Jun 23 '12 at 10:19
  • 1
    did you find the solution? – artman Nov 10 '15 at 12:30
  • @artman Check Pdroid's solution, it seems to be working. I didn't try it as this problem is not actual for me anymore. Also, take a notice here if it works, please. – Prizoff Nov 10 '15 at 21:47

1 Answers1

-1

Just do this :

CitySelectPreference preference = (CitySelectPreference) findPreference("city_pref_key")

//You have to set a key to yout PreferenceScreen
PreferenceScreen screen = (PreferenceScreen) findPreference("screen_pref_key");

//Retrieve the index of the preference in preferenceScreen
int index = preference.getOrder();

//Perform a click
screen.onItemClick(null, null, index, 0); 
Pdroid
  • 867
  • 9
  • 13