开发者

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 i开发者_如何学Cs also debugged by Eclipse: The local variable alert is never read.

Yes I'm a noob.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜