Android - Using PreferenceScreen to display and save settings to/from ContentProvider?

Lookup the available methods in the Documentation You can subscribe to onDialogClosed to get the OK or Cancel click event Also look into getEditText method that will return the edittext of the Dialog, and you can set the value there. Or even look into setText you maybe can set the value with it. This later untested by me EDIT 1 Sorry, you can't subscribe.

You have to subclass the EditTextPreference and override the method. A complex example is here but you don't need all the stuff You are interested in this: Override //When the dialog is closed, perform the relevant actions protected void onDialogClosed(boolean positiveResult) { if (positiveResult) { String text=getEditText().getText().toString(); } else { // cancel hit } } EDIT 2 You have to drop etl = new EditTextListener(this) You have to implement your new class EditTextPreference editTextPref = new EditTextListener(this) so the code will become Edit text preference EditTextPreference editTextPref = new EditTextListener(this); editTextPref. SetDialogTitle(R.string.

Dialog_title_edittext_preference); editTextPref. SetKey("edittext_preference"); editTextPref. SetTitle(R.string.

Title_edittext_preference); editTextPref. SetSummary(name); dialogBasedPrefCat. AddPreference(editTextPref).

Lookup the available methods in the Documentation. You can subscribe to onDialogClosed to get the OK or Cancel click event. Also look into getEditText method that will return the edittext of the Dialog, and you can set the value there.

Or even look into setText, you maybe can set the value with it. This later untested by me. EDIT 1 Sorry, you can't subscribe.

You have to subclass the EditTextPreference and override the method. A complex example is here but you don't need all the stuff You are interested in this: @Override //When the dialog is closed, perform the relevant actions protected void onDialogClosed(boolean positiveResult) { if (positiveResult) { String text=getEditText().getText().toString(); } else { // cancel hit } } EDIT 2 You have to drop etl = new EditTextListener(this); You have to implement your new class EditTextPreference editTextPref = new EditTextListener(this); so the code will become // Edit text preference EditTextPreference editTextPref = new EditTextListener(this); editTextPref. SetDialogTitle(R.string.

Dialog_title_edittext_preference); editTextPref. SetKey("edittext_preference"); editTextPref. SetTitle(R.string.

Title_edittext_preference); editTextPref. SetSummary(name); dialogBasedPrefCat. AddPreference(editTextPref).

– Donal Rafferty Mar 24 '10 at 14:07 Thanks for that, I'm nearly there I think, I have revised my code in my question to show you what I have now my class extends PreferenceActivity So I had to create a sub class called EditTextListener and have it extend EditTextPreference and implement the onDialogClosed method. I then create a new EditTextListener (etl) and pass it the activity as a context. But it still doesn't work, Am I doing it wrong?

– Donal Rafferty Mar 24 '10 at 15:31 1 As I see from here, you need just a small change. See my 2nd edit. – Pentium10 Mar 24 '10 at 19:15.

I have my own custom Content Provider that loads a database which contains the settings information for my application. I load the settings from the ContentProvider on the creation of my Settings activity. My Settings activity is made up of a PreferenceScreen and Dialog based EditText's.

The following code shows how I use the preference screen and edit texts. So as you can see from the first image this works and displays the menu with the information underneath. The problem is in image two, when I click on a choice in the menu the dialog pops up but it is empty, I would like to be able to load the data from my content provider into the edit text in the dialog, so in image one it shows "Donal" as the user name so in image two "Donal" should also appear in the edit text in the dialog.

I would also like to be able to listen to the OK button in the dialog so when a user changes a setting I can update the data in my content provider.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions