我正在與AlertDialog
用戶登錄到應用程序。我已經顯示了兩個編輯視圖,用於輸入用戶名和密碼,並且我還在警報對話框上使用了正面按鈕和負面按鈕。當用戶輸入無效的用戶名或密碼時,則點擊確定我正在用TexView在同一個警報對話框上顯示一個文本,但警報對話框正在關閉。如何保持警報對話框直到用戶在編輯文本域中輸入有效的詳細信息?如何在用戶輸入無效值時返回相同的警報對話框,然後單擊確定?
我已經實現了讓警報如下代碼:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Login here");
alert.setView(table);
alert.setPositiveButton("Login", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
objLogin.setLoginUsrName(userNameText.getText().toString());
objLogin.setLoginPassword(passwordText.getText().toString());
if(objLogin.userValid())
{
//getting next screen
}
else{
invalid.setText("Invalid user name or password");
invalid.setTextColor(Color.RED);
//diaplay same alert here with invalid text
}
}
});
alert.setNegativeButton("Register", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//get register screen code here
}
});
alert.show();
我怎麼能顯示警報,直至用戶輸入有效的細節?
創建一個自定義對話框,而是如何關閉警告對話框,當用戶是有效的? – 2012-02-17 04:07:46
在onClick()方法內調用'alert.dismiss();'。你將不得不提醒''最後'變量,但這應該是好的。 – edthethird 2012-02-17 04:46:12