M M
M M

Reputation: 187

Simplest Dialog

I'm trying to do the equivalent of the simplest kind, VB's MsgBox "Hello, World." (VB automatically apends an [OK] button to that.)

But the following doesn't display at all (i.e., it doesn't work), and I don't know if it can be made simpler either:

AlertDialog.Builder builder = new AlertDialog.Builder(SomeClass.this);
builder.setMessage("Hello, World.")
.setCancelable(true)
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();

The last statement is also debugged by Eclipse: The local variable alert is never read.

Yes I'm a noob.

Upvotes: 1

Views: 209

Answers (2)

om252345
om252345

Reputation: 2415

You need to call show() method on AlertDialog.Builder........show(); in the end

 new AlertDialog.Builder(SomeClass.this);
builder.setMessage("Hello, World.")
.setCancelable(true)
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
}).show();

Upvotes: 3

Jonas m
Jonas m

Reputation: 2734

Try give it a alert.show(); after AlertDialog alert = builder.create();

Upvotes: 2

Related Questions