Using Dialog
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.setup_time);
dialog.setTitle("Title...");
dialog.show();
}
Using Dialog Builder
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
setContentView(R.layout.setup_time);
alertDialogBuilder.setTitle("Enter the Details");
LinearLayout lila1= new LinearLayout(this);
lila1.setOrientation(1); //1 is for vertical orientation
final EditText input = new EditText(this);
final EditText input1 = new EditText(this);
lila1.addView(input);
lila1.addView(input1);
alertDialogBuilder.setView(lila1);
// create alert dialog
// set dialog message
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
No comments:
Post a Comment