Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> Stack Overflow 排錯翻譯,stackoverflow

Stack Overflow 排錯翻譯,stackoverflow

編輯:關於android開發

Stack Overflow 排錯翻譯,stackoverflow


Stack Overflow 排錯翻譯  - Closing AlertDialog.Builder in Android -Android環境中關閉AlertDialog.Builder

轉自:http://www.lanqibing.com/archives/783.html

 

原文:

In the following code, I tried to dismiss the AlertDialog box but to no avail. However, if I remove compareKeys() function, the dismiss will work. So how can I make it dismiss after calling the compareKeys() function?

翻譯:

在下面的代碼中,我嘗試去釋放AlertDialog對話框,但釋放無效。然而,我去掉 compareKeys()方法後,釋放AlertDialog是正常工作的。我如何在釋放AlertDialog對話框後正常調用compareKeys()方法?

 1 public void promptAdministratorPassword() {
 2     AlertDialog.Builder alert = new AlertDialog.Builder(this);
 3 
 4     alert.setTitle("Alert!");
 5     alert.setMessage("Please enter your password: ");
 6 
 7     // Set an EditText view to get user input
 8     final EditText input = new EditText(this);
 9     alert.setView(input);
10 
11     alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
12         public void onClick(DialogInterface dialog, int whichButton) {
13             password = input.getText().toString();
14 
15             if (password.equals("password")) {
16                 try {
17                     compareKeys();
18                 } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException e) {
19                     e.printStackTrace();
20                 }
21             }
22             dialog.dismiss();
23         }
24     });
25 
26     alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
27         public void onClick(DialogInterface dialog, int whichButton) {
28             // Canceled.
29         }
30     });
31     alert.show();
32 }

 

解決方案原文:Call dialog.dismiss() before password = input.getText().toString() and add dialog.dismiss() inside setNegativeButton's OnClickListener too.

解決方案翻譯:將password = input.getText().toString()放到調用dialog.dismiss()之前,並將dialog.dismiss()放到setNegativeButton的OnClickListener方法中。

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved