Kuwame Brown
Kuwame Brown

Reputation: 533

AlertDialog with single button?

I really want to make an AlertDialog with single button, can someone guide me with this. Thanks!

Upvotes: 1

Views: 2756

Answers (2)

Robby Pond
Robby Pond

Reputation: 73484

Use AlertDialog.Builder.

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public onClick(DialogInterface dialog, int which) {
        // do something interesting.
    }
});
// other code to customize the dialog
Dialog d = builder.create();

Upvotes: 0

james
james

Reputation: 26271

Yes you can:

new AlertDialog.Builder(this)
.setIcon(R.drawable.icon)
.setTitle("Error")
.setMessage("Please fill out the entire form")
.setPositiveButton("Close", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {

    }
})
.create()
.show()
;

Upvotes: 3

Related Questions