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

  • SEARCH
  • Home
  • 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 8164969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:25:55+00:00 2026-06-06T19:25:55+00:00

I want put a button on android edittextpreference. I create a custom editextpreference: public

  • 0

I want put a button on android edittextpreference.
I create a custom editextpreference:

public class EditTextPreferenceWithButton extends EditTextPreference {

    private Context context;

    public EditTextPreferenceWithButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context=context;
      }

      public EditTextPreferenceWithButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
      }

      public EditTextPreferenceWithButton(Context context) {
        super(context);
        this.context=context;
      }



      @Override
        protected void onBindDialogView(View view) {
            super.onBindDialogView(view);



           view.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));



            final EditText editText = (EditText)view.findViewById(android.R.id.edit);
            ViewGroup vg = (ViewGroup)editText.getParent();

            Button button = new Button(context);


            vg.addView(button,ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);


        }
}

In this way the button is show below the edit text, but I want it is next the edittext like this:

|EditText| |Button|

Please help me!
Thank you

  • 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-06-06T19:25:56+00:00Added an answer on June 6, 2026 at 7:25 pm

    I would create a subclass of DialogPreference.

    class EditTextDialogPreference extends DialogPreference {
    
        //Layout Fields
        private final LinearLayout layout = new LinearLayout(this.getContext());
        private final EditText editText = new EditText(this.getContext());
        private final Button button = new Button(this.getContext());
    
    
        //Called when addPreferencesFromResource() is called. Initializes basic paramaters
        public EditTextDialogPreference(Context context, AttributeSet attrs) {
            super(context, attrs);
            setPersistent(true);
            button.setText("Button");
            layout.setOrientation(LinearLayout.HORIZONTAL);
        }
    
        //Create the Dialog view
        @Override
        protected View onCreateDialogView() {
            layout.addView(editText);
            layout.addView(button);
            return parentLayout;
        }
    
        //Attach persisted values to Dialog
        @Override
        protected void onBindDialogView(View view) {
            super.onBindDialogView(view);
            editText.setText(getPersistedString("EditText"), TextView.BufferType.NORMAL);
        }
    
        //persist values and disassemble views
        @Override
        protected void onDialogClosed(boolean positiveresult) {
            super.onDialogClosed(positiveresult);
            if (positiveresult && shouldPersist()) {
                persistString(editText.getText().toString());
            }
    
            ((ViewGroup) editText.getParent()).removeView(editText);
            ((ViewGroup) button.getParent()).removeView(button);
            ((ViewGroup) layout.getParent()).removeView(layout);
    
            notifyChanged();
        }
    }
    

    I’m assuming you’re going to persist the value in the EditText and I’m leaving the action of the button up to you. See this post for more information on the in’s and out’s of extending DialogPreference.

    In order to get the key into the SharedPreferences, put the following in your XML:

    <com.yourpackage.EditTextDialogPreference
        android:key="Your Key"
        android:persistent="true"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to put two buttons in listView. public class Imenik extends ListActivity {
i want to put Go button in android appliation softkeyboard for search and other
I want to quit application in Android. Just put a quit button, which kills
Hi i want to put button beside activity title in android. I can change
Problem: I want to put Twitter Share Button in my Google Map InfoWindow. I
I want to put an image on a button, but I want part of
hey, hi i want put limit on object creation means a class can have
I am trying to make custom button below is the code. I want to
I want to put a button next to a EditText and I want their
I want to put a close button in a web page (our client wants

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.