Alert Dialog with EditText in Android Example with Source Code

Alert Dialog with EditText in Android Example with Source Code

Here we will learn how to user Alert Dialog with EditText in Android example with source code description. Also you can download complete source code from here. It’s very simple. We have already discussed how to create and use a simple Alert Dialog in Android.
Now we will learn how to use an EditText with an Alert Dialog in Android, so that you can get required text inputs (Example getting User Name and Password from user) along with OK/YES, CANCEL/NO button. If you want to learn how to use simple alert dialog in Android, then you might like my article ‘Alert Dialog in Android Example with Source Code and Description‘.

Only we will add 2 more lines of code with simple Alert Dialog source code. That’s it. However we will find the complete source code for Alert Dialog with EditText in Android here.

Code Snippet for EditText in Alert Dialog in Android

Here we will add the below 2 lines of code along with simple Alert Dialog source  code. Put the below code snippet in your onClick listener code after creating the Alert Dialog. This code snippet will add an extra EditText Box in to the Alert Dialog. We will discuss complete code later in this post.

Note: You can also add more than one EditText by repeating the above steps with different variables.


  1. First, we will use the AlertDialog.Builder defaul android class to create the alert box interface for title, message to display, buttons, and button onClick function.
  2. Then We will create a EditText Box dynamically and we will attach this EditText box with the simple Alert Dialog.
  3. Then We will attach above builder to AlertDialog.
  4. Then we will display it.
  5. Done.

Complete Alert Dialog with EditText Box Source Code and Description

We have used one button for the Alert Dialog  project,  so that we can show the Alert Dialog Box when we will click on that button.

  • Create new android project [File >> New >> Android Project] with Project Name: AlertDialogExample
  • Click next and select target android device version [I chose version 2.2]
  • Click next and enter package name – ‘com.techblogon.alertdialog’
  • Click finish

Layout creation:

Default Application layout – main.xml:

Open main.xml under /res/layout and replace it with the below XML.


Now Coming to the Java File (

Here we will find the complete java code for Android Alert Dialog.


downloadYou can also download complete code from here Alert Dialog Example With EditText in Android.

That’s It. Enjoy your Alert Dialog in Android. For other types of Alert Dialog, You can click Here or click on “Previous Page” button below.


Post By SmrutiRanjan (57 Posts)

Working @ Samsung as a Project Lead for Android Smartphones. I have been blogging since 2008. Previously I was writing articles for other bloggers, but finally I have started my own blog-"Techblogon".I am also an active contributor for the blog-"Gadgets n Gizmos World". Job is my necessity, but blogging is my passion.

Website: → Techblogon


12 Responses to Alert Dialog with EditText in Android Example with Source Code

  1. retro jordans says:

    Adding this to twitter great info.

  2. dystrybutor wysłodzin says:

    I just like the valuable information you supply in your articles. I will bookmark your blog and take a look at again right here regularly. I am somewhat sure I will be informed many new stuff proper right here! Best of luck for the following!

  3. vinny says:

    i think its awwsm but tell me can we take 2 edit text and 2 button ,,,,,, and 2 text views and 2 swwkbars in dialog box ,,, ?????????? please

  4. vinny says:

    Select all or required packages & proceed.

  5. wira says:

    get rid of the tweet bird man it’s annoying. good article though

  6. zeeshan says:

    It is so simple, thanx

  7. zeeshan says:

    how we can use Spinner view instead of EditText in dialogBox?????

  8. Sandip Borad says:

    Nice but how i can create folder using alert dialog and set as all folder in listview ??

Leave a Reply

Your email address will not be published. Required fields are marked *

7 − = zero

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">