Add custom control on Dialog in android 

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.

Dialogs inform users about critical information, require users to make decisions, or encapsulate multiple tasks within a discrete process. Use dialogs sparingly because they are interruptive in nature. Their sudden appearance forces users to stop their current task and refocus on the dialog content. Not every choice, setting, or detail warrants interruption and prominence.

 Alternatives to dialogs include menus or inline expansion within the current content area. Both approaches present non-interruptive options while maintaining the current context.

You can add custom control in dialog for example edittext , textview buttons etc. Here I am creating a dialog with using custom button.

      final Dialog dialog = new Dialog(MainActivity.this);


                 LinearLayout popUp = new LinearLayout(MainActivity.this);




                 LinearLayout btnLayout = new LinearLayout(MainActivity.this);





                     Button btnOne = new Button(MainActivity.this);



                     Button btnTwo = new Button(MainActivity.this);



                     dialog.setTitle("Select Action");









                           btnOne.setOnClickListener(new OnClickListener() {



                           public void onClick(View v) {

                               // TODO Auto-generated method stub

                   Toast.makeText(MainActivity.this, "Button one clicked",                  Toast.LENGTH_LONG).show();





     btnTwo.setOnClickListener(new OnClickListener() {



                           public void onClick(View v) {

                                // TODO Auto-generated method stub

                       Toast.makeText(MainActivity.this, "Button two clicked", Toast.LENGTH_LONG).show();







   You can see dialog.


Leave Comment