我想在一个活动上做一个密码警告框,所以一旦它有正确的答案就会关闭对话框,但我似乎无法找到一种方法来搜索如何以我编码方式关闭对话框.
这是我的代码
final AlertDialog.Builder alert1 = new AlertDialog.Builder(this);
alert1.setTitle("Password");
alert1.setMessage("Please enter your password below and press Ok.");
final EditText input = new EditText(this);
alert1.setView(input);
alert1.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString().trim();
((Global) Menu.this.getApplication()).setgPassword(value);
((Global) Menu.this.getApplication()).setgSiteId(strSavedMem1);
LogIn();
}
});
alert1.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
System.exit(0);
}
});
alert1.show();
Run Code Online (Sandbox Code Playgroud)
有没有办法关闭此警报框?
小智 7
您应该查看Android文档的此链接:http: //developer.android.com/guide/topics/ui/dialogs.html#DismissingADialog
在那里解释了如何取消对话.
您可以在DialogInterface onClick方法中接收对话框实例.
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16863 次 |
| 最近记录: |