I have a very simple custom dialog and I wan't to add a positive button without having to modify the XML file, just like you would do it with an AlertDialog but I don't know if it's possible. This is the code:
final Dialog dialog = new Dialog(MyActivity.this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Settings");
dialog.show();
setPositiveButton(String, DialogInterface. OnClickListener) to set up your buttons. Finally, use AlertDialog myAlertDialog = myAlertDialogBuilder. create() to get your instance of AlertDialog, which you can then further customize with methods such as setCancelable() .
When user click yes button it will show yes message, no button shows no message and neutral button for neutral message. In the above result, it shown initial screen. Now click on button it will open dialog with yes, no, and neutral buttons.
Alert Dialog allows maximum three action buttons in a dialog.
You should use the builder.
LayoutInflater inflater = LayoutInflater.from(this);
View dialog_layout = inflater.inflate(R.layout.dialog,(ViewGroup) findViewById(R.id.dialog_root_layout));
AlertDialog.Builder db = new AlertDialog.Builder(MyActivity.this);
db.setView(dialog_layout);
db.setTitle("settings");
db.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = db.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With