我的AlertDialog有点问题。当我把它放在一个Button的onClick-Listener中时,代码运行得很好,但是当我把它放在main-method的末尾时,它根本就不能工作。
这是显示AlertDialog的方法:
void showMaths(){
AlertDialog.Builder alert = new AlertDialog.Builder(LabyRiddle.this);
alert.setTitle("Title");
alert.setMessage("Message");
// Set an EditText view to get user input
final EditText input = new EditText(LabyRiddle.this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.create(); // <== Doesn't make any difference whether its here or not
alert.show();
}我只想让main-method运行,并在它的末尾出现警告...
但它不会出现,也不会崩溃,甚至不会给出错误报告。
或者,是否可以在main方法完成后显示警报?
谢谢,祝你有愉快的一天!
奥利弗
发布于 2013-01-22 01:30:34
我想你应该打电话给我
alert.create().show();在调用show();之前,必须使用create();方法从构建器创建对话框
发布于 2013-01-22 01:33:37
你忘了打这条线路
alert.create();在此之前
alert.show();
有关警报对话框的详细信息,请参阅此链接http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog
https://stackoverflow.com/questions/14444064
复制相似问题