Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 678317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:08:10+00:00 2026-05-14T01:08:10+00:00

I have my own custom Content Provider that loads a database which contains the

  • 0

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.

Can anyone help me with what I’m trying to do?


Code

public class PreferencesApp extends PreferenceActivity {

String name;
EditTextListener etl;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    loadSettingsFromProvider();
    etl = new EditTextListener(this);

    setPreferenceScreen(createPreferenceHierarchy());
}

private PreferenceScreen createPreferenceHierarchy() {
    // Root
    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);

    // Dialog based preferences
    PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this);
    dialogBasedPrefCat.setTitle(R.string.dialog_based_preferences);
    root.addPreference(dialogBasedPrefCat);

    // Edit text preference
    EditTextPreference editTextPref = new EditTextPreference(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);


    return root;
}

public class EditTextListener extends EditTextPreference{

    public EditTextListener(Context context){

        super(context);

    }

    @Override
    //When the dialog is closed, perform the relevant actions
    protected void onDialogClosed(boolean positiveResult) {

        if (positiveResult) {
         String text=getEditText().getText().toString();
         Log.d("DIALOG CLOSED", "OK");
         }
        else {
         // cancel hit
         Log.d("DIALOG CLOSED", "CANCEL");
        }
    }       
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:08:11+00:00Added an answer on May 14, 2026 at 1:08 am

    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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have our own custom calendar in our portal which is developed in Java.
So I have implemented my own custom membership provider, currently only overwriting ValidateUser(). I
I have a data Store that gets it's information from a JSON api on
I have my own custom tool for Visual Studio 2008 SP1. It consists of
I have my own custom UISegmentedControl subclass. It's buttons are bigger than the standard
I would like to have my own custom change_password page and I am already
I have an XML layout and want to add my own custom SurfaceView to
I have created a custom list view, each row has it's own custom selector,
In my installer I have set WixUIBannerBmp to point to my own custom dialog-banner.bmp
I have a custom windows service with my own register handler, how can I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.