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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:43:24+00:00 2026-06-01T09:43:24+00:00

I want to show a Dialog with an EditText . I envision it having

  • 0

I want to show a Dialog with an EditText. I envision it having two buttons: a positive button, which will persist the text contained in the EditText, and a negative button, which will cancel and return to the Activity that launched it as if nothing had happened. I have tried using an AlertDialog with no success:

AlertDialog.Builder builder = new Builder(context);
final EditText text = new EditText(context);

builder.setTitle("New Profile").setMessage("Name this new profile").setView(text);
builder.setPositiveButton("Create", new OnClickListener() {

    public void onClick(DialogInterface di, int i) {
        final String name = text.getText().toString();
        //do something with it
    }
});
builder.setNegativeButton("Cancel", new OnClickListener() {

    public void onClick(DialogInterface di, int i) {
    }
});
builder.create().show();

Am I doing something wrong with the setView() method? Would using a custom Dialog be more practical?

EDIT:

I’ve gotten several answers saying the code works for them… not sure why it isn’t working for me. Here’s the logcat:

E/AndroidRuntime(  326): FATAL EXCEPTION: main
E/AndroidRuntime(  326): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
E/AndroidRuntime(  326):    at android.view.ViewRoot.setView(ViewRoot.java:531)
E/AndroidRuntime(  326):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
E/AndroidRuntime(  326):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/AndroidRuntime(  326):    at android.app.Dialog.show(Dialog.java:241)
E/AndroidRuntime(  326):    at com.gobernador.TopPage.onListItemClick(TopPage.java:77)
E/AndroidRuntime(  326):    at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
E/AndroidRuntime(  326):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime(  326):    at android.widget.ListView.performItemClick(ListView.java:3513)
E/AndroidRuntime(  326):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
E/AndroidRuntime(  326):    at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(  326):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(  326):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  326):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(  326):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  326):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(  326):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(  326):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(  326):    at dalvik.system.NativeStart.main(Native Method)
  • 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-01T09:43:25+00:00Added an answer on June 1, 2026 at 9:43 am

    gobernador Agarwal is right , i also tried you code and it was working , try it by replacing context with this

    AlertDialog.Builder builder = new Builder(this);
            final EditText text = new EditText(this);
    
            builder.setTitle("New Profile").setMessage("Name this new profile").setView(text);
            builder.setPositiveButton("Create", new OnClickListener() {
    
                public void onClick(DialogInterface di, int i) {
                    final String name = text.getText().toString();
                    //do something with it
                }
            });
            builder.setNegativeButton("Cancel", new OnClickListener() {
    
                public void onClick(DialogInterface di, int i) {
                }
            });
            builder.create().show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show a dialog that will allow the user to select a
I want to show a dialog on my activity with animation. My dialog will
I want to click a edittext and show dialog date so I try mDateDisplay
I want to show a dialog box with an OK button that is disabled
I am making an alert dialog with edit text. I want that it will
I want to show a jquery ui dialog , if user will reload, close
I want to show a dialog (kind of splash screen) when my application is
I want to show some dialog (absolute positioned div), and I want to show
I want to show a open dialog for the user, where the user can
I want to show a modal dialog/pop-up window when the user has not filled

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.