开发者

Simplest Dialog

开发者 https://www.devze.com 2023-04-13 07:33 出处:网络
I\'m trying to do the equivalent of the simplest kind, VB\'s MsgBox \"Hello, World.\"(VB automatically apends an [OK] button to that.)

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

精彩评论

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

关注公众号