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.
Related
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
I have a list of options that are shown in an AlertDialog. The AlertDialog populates the list from a SharedPreferences file. Currently the user makes a selection, the AlertDialog closes and depending on the choice some edit text fields are filled in.
I would like to add an OnLongClickListener call to each option in the list, which when utilized would pop up another AlertDialog, over the top of the existing one, with a simple "are you sure you want to delete this?" question, then a yes and no button.
The dialog creation is simple, I just want to know if the OnLongClickListener can be applied and if AlertDialogs can be down on top of each other?
my answer here may help with adding an OnLongClickListener. The code I added is at the bottom of my response.
You can accomplish what you want by setting a new OnShowListener on your dialog and overriding the onShow() method
My desired custom preference looks very much like the out-of-box EditTextPreference, only that it behaves like a "split button" which combines two Preferences: if user clicks on the text on the left, the edit text dialog pops up; which allows user to set the "label" for the preference; if user clicks on the button on the right, another window pops up that allows user to set the "date" for the preference.
I guess I could extend EditTextPreference but I am not sure how I can maintain two separate keys for a single preference control (or "widget" in Android's term). Or is it possible to "mix up" two Preferences without subclassing?
Really you do not have to use the built in preference widgets to manage your preferences; for example, in my application, i use a PreferenceScreen to bring up a multiple selection dialog with a custom listview/adapter. If you wish to handle your own key/value store, you could bind to the preference with findPreference(), set the value in the PreferenceActivity's onCreate() and persist the value in the activity's onPause(). Examining the key / value preference store can be done via getSharedPreferences(file,MODE.PRIVATE) and an associated getter method. To edit them, take the SharedPreferences object that's returned and call edit() / commit() on it once changes have been made.
Does this answer you question?
I was trying to make my UI as neat as possible,
The user should enter some values into a circuit diagram,so I was trying to make the user click the resistor for example, then, a pop-up window appear with an EditText field in it for the user to enter the value of the resistor.
So far I was able to do that by using two separate setContentView()s, one for the circuit diagram and the other holds the EditText field, but I want the layout with the circuit Diagram to be visible in the background while the pop-up is the one in focus.
something like this (random example from the web):
http://blog.itechtalk.com/wp-content/2010/10/SMS-Popup-1.png
You are looking for a dialog. See creating dialogs.
Actually smsmpopup uses an activity with theme dialog in it's manifest. Check the src code.
yes.. u want something as a Dialog... but if its an activity.. u can set this paramenter in the androidmanifest file..
android:name=".Pick_Color"
android:label="Pick a Color !"
android:theme="#android:style/Theme.Dialog">
this will make the screen as neat and Dialogish as possible
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.