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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:44:52+00:00 2026-05-20T06:44:52+00:00

I am writing a simple android app which have a edittext and a button.

  • 0

I am writing a simple android app which have a edittext and a button. Clicking on button should display an alert dialog with text entered in the edittext. For that I have the following code:

String txt; 
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button b=(Button)findViewById(R.id.ok);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Text in edit box: " + txt)
        .setCancelable(false)
        .setTitle("Info")
        .setPositiveButton("Done", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int id) {}
    });

    final AlertDialog alert = builder.create();

    // set click listener on the flag to show the dialog box 
    b.setOnClickListener(new View.OnClickListener() {
       public void onClick(View v) {
          EditText et=(EditText)findViewById(R.id.entry);
          txt=et.getText().toString();
          alert.show();
       }
    });

}

The above code is running fine but the alert dialog shows Text in edit box: null.It should show the text of the editbox.

  • 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-20T06:44:53+00:00Added an answer on May 20, 2026 at 6:44 am

    The time the statement

    builder.setMessage("Text in edit box: " + txt)
    

    got executed txt variable has null in it. this the reason.

    Try to get this statement get executed after button click.
    It will 100% for sure remove the problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a simple Android app and have a database that will send
I'm writing a simple app that's going to have a tiny form sitting in
I am writing an Android app, part of which will be a survey involving
I am writing my first simple Android App: It loads temperature samples from a
I am currently writing a simple, timer-based mini app in C# that performs an
I am writing a simple database with web access. I have previous experience with
I am writing an android app. I want to pass some data across the
I'm in the middle of writing an Android app, and would like to give
I'm toying with the Android SDK, with a view to writting a simple app
I'm looking into writing simple graphics code in Android and I've noticed some synchronized()

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.