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 6115429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:05:24+00:00 2026-05-23T15:05:24+00:00

I have a problem with a custom dialog. My dialog consists of a TextView

  • 0

I have a problem with a custom dialog.
My dialog consists of a TextView, EditText and an “Ok” Button. After clicking “Ok”, it should get the text from EditText field and assign it to the String variable “name” defined in the Activity.
Everything seems to work, no errors etc, however “text” is always an empty String.
I read some topics about such problems, however I’m not really sure what adjustments I should make here.
I’m quite new to Android programming, so I’d be grateful if somebody could explain the problem to me. Thanks in advance.

     final Dialog dialog = new Dialog(MyActivity.this);
     dialog.setContentView(R.layout.custom_dialog);
     dialog.setTitle("Title");

     final View layout = View.inflate(this, R.layout.custom_dialog, null);
     Button button = (Button) dialog.findViewById(R.id.dialog_ok);
     button.setOnClickListener(new OnClickListener() {
         public void onClick(View v) {
                EditText edit=(EditText)layout.findViewById(R.id.dialog_edit);
                String text=edit.getText().toString();

                name=text;

                dialog.dismiss();
         }
     });   

     dialog.show();
  • 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-23T15:05:25+00:00Added an answer on May 23, 2026 at 3:05 pm

    You are inflating a layout where it is not needed. I fixed your code as you see I removed your line where it inflates and changed the line where you try to find the EditText view.

    final Dialog dialog = new Dialog(MyActivity.this);
     dialog.setContentView(R.layout.custom_dialog);
     dialog.setTitle("Title");
    
     Button button = (Button) dialog.findViewById(R.id.dialog_ok);
     button.setOnClickListener(new OnClickListener() {
         public void onClick(View v) {
    
                EditText edit=(EditText)dialog.findViewById(R.id.dialog_edit);
                String text=edit.getText().toString();
    
                dialog.dismiss();
                name=text;
    
         }
     });   
    
    
    dialog.show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom dialog, the code is below. The problem is that,
I have a custom dialog in my app that descends from Activity and uses
I have a problem creating a custom dialog. But I don't find the failure.
i have a small problem with writing my application.. I have custom dialog what
I have a problem with a custom dialog implemented as below: AlertDialog.Builder dialogBuilder =
I have a little problem with an android custom dialog. I construct a custom
here I have a custom dialog with background 2 ImageButton inside it. the problem
I have some main activity and clicking on a button it launches a custom
I have problem with casting custom event currentTarget to component. When I'm trying to
I have a problem with leaking custom cells. In my overridden UITableViewController, I have,

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.