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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:43:13+00:00 2026-05-21T22:43:13+00:00

On the Android I’m trying to turn an Edittext to a string. The toString()

  • 0

On the Android I’m trying to turn an Edittext to a string. The toString() method doesn’t work, playerName is null when I print it out. Are there any other ways to turn an edittext to a string?

AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setMessage("Your Name");
        final EditText input = new EditText(this);
        alert.setView(input);
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                playerName = input.getText().toString();
            }
        });
        alert.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-21T22:43:14+00:00Added an answer on May 21, 2026 at 10:43 pm

    the alertdialog looks fine, but maybe the error is located in the rest of the code. You have to keep in mind that you are not able to use the var playerName just beneth the show() of the dialog, if you want to print out the name you should do this with a runnable wich you call here:

          static Handler handler = new Handler();
    
          [.......]
    
          public void onClick(DialogInterface dialog, int whichButton) {
                playerName = input.getText().toString();
                handler.post(set_playername);
    
          }
    
          [.......]
    
         static Runnable set_playername = new Runnable(){
                @Override
                public void run() {
            //printout your variable playerName wherever you want
        }
      };
    

    edit to clarify:

    AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setMessage("Your Name");
        final EditText input = new EditText(this);
        alert.setView(input);
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                playerName = input.getText().toString();
                //call a unction/void which is using the public var playerName
            }
        });
        alert.show();
        // the variable playerName is NULL at this point
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

android:layout_gravity=center doesn't seem to work the same in a RelativeLayout as it does in
In Android, is there a similar method to the repaint() in java?
In Android, when layout out widgets, what's the difference between fill_parent ( match_parent in
In my Android application, when I rotate the device (slide out the keyboard) then
Android: I am trying the following xAuth example for android share. xAuth Authentication for
Android API level 8 introduced the Context.getExternalFilesDir() method, providing a File object reference to
In Android, is there a way to get a list of the zip files
I'm trying to write test harness for part of my Android mapping application. I
Android documents starting the email intent for sending emails with Intent.ACTION_SEND. Is there an
Android 2.3 is coming out soon. I was curious if anyone knew if android

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.