JoeyCK JoeyCK - 1 year ago 122
Android Question

Add positive button to Dialog

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);

amp amp
Answer Source

You should use the builder.

LayoutInflater inflater = LayoutInflater.from(this);
View dialog_layout = inflater.inflate(R.layout.dialog,(ViewGroup) findViewById(;
AlertDialog.Builder db = new AlertDialog.Builder(MyActivity.this);
db.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
AlertDialog dialog =;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download