DIalogPreference Problem - android

I am using preferences, and this snippet of XML always causes my application to stop unexpectly when I hit a menu settings button which is supposed to display a list of preferences. I can use CheckBoxPreference and ListPreference successfully but I cannot use DialogPreference. I cannot seem to find an example XML snippet anywhere.
I need this dialog to collect a phone number in a string.

I should have been using EditTextPreference which extends DialogPreference. This works.

Related

Android EditTextPreference show value in summary

I would like to show the preference value in the summary field. This accepted answer shows how to do it for a ListPreference.
Is there a similar way to do it for an EditTextPrefernce in the layout instead of extending the class?
I just have a little method that updates the preference summary every time a preference changes. I found this somewhere online back when I needed it but unfortunately I don't remember where to credit :(
Edit: Nevermind, I found the source.
https://stackoverflow.com/a/4325239/3238938

Create Android preference in settings to set password

I would like a setting in preferences that allows the user to create a password. The perfect example is in the Play Store. In settings you click on Password and a dialog box pops up with an EditText field with a password field that hides the characters. How would you do that?
I'm pretty sure this is not EditTextPreference. Is this a custom preference? How would you make this? Can I get a sample for the XML part of it?
I'm pretty sure this is not EditText preference
EditTextPreference would work. Quoting the documentation:
This EditText can be modified either programmatically via getEditText(), or through XML by setting any EditText attributes on the EditTextPreference.
So adding android:password="true" as part of your preference XML should work.
That being said, you are certainly welcome to create your own custom DialogPreference for this.
Using intents
In some cases, you might want a preference item to open a different activity instead of a settings screen, such as a web browser to view a web page. To invoke an Intent when the user selects a preference item
it's available at android guide, check this link
http://developer.android.com/guide/topics/ui/settings.html#Intents

How can I change the appearance of ListPreference **Button**

There are a lot of questions around how to customize a ListPreference with images on each row and so on.
What i m interested is, however, the button that opens up the list dialog.
For example, for the sync frequency :
Is there a way to replace the generic listpref button with an image button ?
Thanks in advance!
You can simply use the android:icon attribute to add an image to your ListPreference entry.
Documentation

How to have custom dialog on preference activity?

I have a preference page where there is a check box preference for enable login password. When the user check it, it should have a dialog pop out and inside there will be 2 edit text fields for password.
I have done some readings and it seems like using a custom dialog will be the right choice. But the problem is that there is no onCreateDialog() method for the preference activity to override, how do I solve this problem?
Some example codes will be nice. Thanks!
Create your own custom subclass of DialogPreference that handles your dialog and persists your preference value, and use that in your preference XML resource.

Access a shared-preference listPreference directly, without having to enter the menu first! (Android)

I have no idea how to achieve this, and don't know if it's achievable or not.
I have a sharedPreference value I set via my android app like this
menu button -> settings -> listPreference (a 1 digit value is set this way, among 3 values!!!)
I would however like to be able to set this value without entering the settings menu first, because it is changed often. Im thinking a button should take me directly to the listPreference dialog box like this!
Button -> listPreference
Is is possible to omit the settings menu like this?
Thanks
I asked somthing similar some time back. There is no quick solution but I have a coded up custom solution in the answer to this question

Categories

Resources