Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is something that is missing in the documentation, and I've found lots of similar questions regarding it, mostly with no definite answers. I've faced the same problem today, and somehow I've found the solution, so I'll summarize my quest here, just in hope someone will find this useful. BTW your question is the most detailed and accurate among others.</p> <p>The general point is that you don't need to create the dialog manually, you just 1) create a subclass of the DialogPreference that will handle the logic of a complex preference and 2) create a node of the proper type in your preferences.xml so the dialog will be spawned automatically.</p> <p>The problem of the Android SDK is that you cannot add that proper node using the visual XML editor, you need to go and edit the file manually.</p> <p>The problem of the documentation is that it misses this very bit of information.</p> <p>So here is the step-by-step solution:</p> <p>1) Create a subclass of DialogPreference that will handle your special preference. For details on what is needed in your subclass, I'd recommend <a href="https://stackoverflow.com/a/4805325/1380150">this answer</a>.</p> <p>2) Create a Preference node in your preferences.xml.</p> <p>3) Edit the preferences.xml and replace the Preference with full name of your DialogPreference subclass including the package path, e. g. com.sample.MyPreferenceDialog. You may also add some attributes to the node to customize the dialog (title, icon, etc.), see <a href="https://stackoverflow.com/a/8818446/1380150">this answer</a> or the documentation for DialogPreference for details.</p> <p>That's all. You don't need to add OnPreferenceClickListener to the preferences, the dialog will show up automatically.</p> <p>Note: I am not 100% sure that this is the intended way of using things, but it seems to be working.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload