0
view.findViewById(R.id.doc_prof_det_add_speciality_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(v.getContext());
                LayoutInflater factory = LayoutInflater.from(v.getContext());
                final View view = factory.inflate(R.layout.doc_prof_det_add_speciality, null);
                alertDialog.setView(view);

            alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });

            alertDialog.show();
        }
    });
JohnPaul
  • 714
  • 5
  • 14
Jack D
  • 119
  • 1
  • 1
  • 11

1 Answers1

1

Try this:

alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });

            alertDialog.show();


           //Grab the window of the dialog, and change the width
           WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
           Window window = alertDialog.getWindow();
           lp.copyFrom(window.getAttributes());
           //This makes the dialog take up the full width
           lp.width = WindowManager.LayoutParams.MATCH_PARENT;
           lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
           window.setAttributes(lp);

    }
}); 
Gulmuhammad Akbari
  • 1,986
  • 2
  • 13
  • 28