Saturday, February 13, 2010

Create a Custom Dialog

This article helps to creating a custom dialog box.

1. Create a Layout.xml for customDialog
Create a new layout which contains the view. in this example i have used edittext and button.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:layout_width="wrap_content" android:layout_height="wrap_content">

    <EditText android:id="@+id/EditText01" android:layout_height="wrap_content" android:text="Enter your name" android:layout_width="250dip"></EditText>

    <Button android:id="@+id/Button01" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="click"></Button>


2. Create a Custom Dialog Class.
a. Create a class extends the dialog class
b. Create a Event Handler Interface as a member
c. Use the custom layout in onCreate Method.

public class MyCustomDialog extends Dialog {

    public interface ReadyListener {
        public void ready(String name);

    private String name;
    private ReadyListener readyListener;
    EditText etName;

    public MyCustomDialog(Context context, String name,
            ReadyListener readyListener) {
        super(context); = name;
        this.readyListener = readyListener;

    public void onCreate(Bundle savedInstanceState) {
        setTitle("Enter your Name ");
        Button buttonOK = (Button) findViewById(;
        buttonOK.setOnClickListener(new OKListener());
        etName = (EditText) findViewById(;

    private class OKListener implements android.view.View.OnClickListener {
        public void onClick(View v) {


3. Create a MainActivity and Implement the CustomDialog
public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        MyCustomDialog myDialog = new MyCustomDialog(this, "",
                new OnReadyListener());;
    private class OnReadyListener implements MyCustomDialog.ReadyListener {
        public void ready(String name) {
            Toast.makeText(MainActivity.this, name, Toast.LENGTH_LONG).show();


  1. Awesome, thanks for posting this code -- I had been struggling and looking at this helped me figure out my problems!

    1. Customize Android Search Dialog Using Library
      In this tutorial, we are going to learn how to implement and customize android search dialog in our android application. Search functionality is one of the major features most android applications have.

  2. thanks
    it really helped!!!!

  3. Useful example. Shouldn't the Layout.xml file above be called mycustomdialog.xml instead?

  4. Any ideas on why I cannot get my code to capture the events generated by my dialog's button?

    Great example. Thanks

  5. Thanks a lot for posting this code

  6. This comment has been removed by the author.

  7. Nice job

    Could you provide something more complicated?
    How to manage Title area?


    Shall we implement AutoComplete for this CustmaizedListView????

  9. Great, i saw a site which is giving the full example for the custom dialog

  10. Thank u so much. It's a good start for custom dialogs :)

  11. thanks! nice codes, very OOP that makes it easy to miplement.

  12. Put the screenshots it will be more clear

  13. good one but how to set the edit text's text to my textview in main activity????

  14. Android Dialog - Android Custom Dialog

    how to create Android Custom Dialg which is for user login, you may have any customized android layout.

  15. Thanks for this helpful post! I compiled a list of some top resources for customizing dialog boxes in android. I included your tutorial. Check it out/ feel free to share. Hope this can be useful to other developers too. :)

  16. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this development course fees in chennai | android app development training in chennai|

  17. The site was so nice, I found out about a lot of great things. I like the way you make your blog posts. Keep up the good work and may you gain success in the long run.
    Click here:
    angularjs training in tambaram
    Click here:
    angularjs6 Training in Chennai

  18. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.
    Click here:
    Microsoft azure training in chennai
    Click here:
    Microsoft azure training in online

  19. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.
    Blueprism training in tambaram

    Blueprism training in annanagar

    Blueprism training in velachery

  20. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    Devops training in velachery
    Devops training in annanagar

  21. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.

    rpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune

  22. All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
    java training in chennai | java training in USA

    java training in indira nagar

  23. I always enjoy reading quality articles by an individual who is obviously knowledgeable on their chosen subject. Ill be watching this post with much interest. Keep up the great work, I will be back

    Data Science course in kalyan nagar | Data Science course in OMR
    Data Science course in chennai | Data science course in velachery
    Data science course in jaya nagar | Data science training in tambaram

  24. When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.

    Amazon Web Services Training in Pune | Best AWS Training in Pune

    AWS Training in Pune | Best Amazon Web Services Training in Pune

  25. Very creativity blog!!! I learned a lot of new things from your post. It is really a good work and your post is the knowledgeable. Waiting for your more updates...
    Blue Prism Training Institute in Bangalore
    Blue Prism Course in Bangalore
    Blue Prism Training Bangalore
    Blue Prism Classes in Bangalore
    Blue Prism Course in Adyar
    Blue Prism Training in Mogappair

  26. More informative,thanks for sharing with us.
    this blog makes the readers more enjoyable.keep add more info on your page.
    Selenium Training Institutes in OMR
    Selenium Courses in OMR
    Selenium Certification Training in T nagar
    Selenium Courses in T nagar

  27. Thanks for the great article this is very useful info thanks for the wornderful post,
    custom software development company.

  28. Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 
    Selenium training in Chennai

  29. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.
    Java training in Chennai

  30. Pleasant Tips..Thanks for Sharing….We keep up hands on approach at work and in the workplace, keeping our business pragmatic, which recommends we can help you with your tree clearing and pruning in an invaluable and fit way.
    angularjs online training

    apache spark online training

    informatica mdm online training

    devops online training

    aws online training

  31. Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing.
    R Training Institute in Chennai | R Programming Training in Chennai

  32. Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
    Thanks & Regards,
    VRIT Professionals,
    No.1 Leading Web Designing Training Institute In Chennai.

    And also those who are looking for
    Web Designing Training Institute in Chennai
    SEO Training Institute in Chennai
    Photoshop Training Institute in Chennai
    PHP & Mysql Training Institute in Chennai
    Android Training Institute in Chennai