2011-01-10 94 views
1

我正在構建一個註冊活動的Android應用程序。當註冊成功時,我想顯示一個警告框,顯示成功消息並返回到父級活動。 問題是警報箱僅顯示一段時間,然後立即返回到父活動,而不按任何警報框中的任何按鈕。 我的代碼是:警報對話框關閉,不按下按鈕

case RESPONSE_USER_SIGNUP_SUCCESS:    
      showAlertBoxSignupSuccess(); 
      Intent returnIntent = new Intent(); 
      returnIntent.putExtra("email", email); 
      setResult(RESULT_OK, returnIntent);   
      this.finish(); 
      break; 

private void showAlertBoxSignupSuccess() 
{ 
    AlertDialog.Builder alertbox = new AlertDialog.Builder(this); 
    alertbox.setTitle("The account was successfuly created"); 
    alertbox.setNegativeButton("OK", new DialogInterface.OnClickListener() { 

     public void onClick(DialogInterface arg0, int arg1) 
     { 
      arg0.dismiss(); 
     } 
    }); 
    alertbox.show(); 


} 

我的問題是,如何才能讓它等到用戶點擊在alertbox按鈕,然後轉到父活動?

謝謝!

回答

5

如果你想等到用戶按下OK按鈕離開當前活動,您應該showAlertBoxSignupSuccess();下面的代碼放入您的按鈕的onClick聽衆:

public void onClick(DialogInterface arg0, int arg1) 
    { 
     arg0.dismiss(); 
     Intent returnIntent = new Intent(); 
     returnIntent.putExtra("email", email); 
     setResult(RESULT_OK, returnIntent);   
     this.finish(); 
    } 
+0

謝謝!它現在有效。 – 2011-01-10 18:34:15

相關問題