0
我有一個自定義AlertDialog與PIN的EditText。使用SharedPreferences檢查正面按鈕OnClick的editText中的PIN。如果匹配,我想關閉對話框,否則它應該保持打開狀態。 當PIN碼正確時,對話框關閉並重新出現,我不希望它重新出現。 感謝您的幫助提前。不能關閉AlertDialog。它不斷彈出
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
if ((System.currentTimeMillis() - mainScreenActivity.lastLoggedIn)/1000 >= 120) {
//startActivity(pinVarificationActivity);
//Toast.makeText(getApplicationContext(),"Session has timed out, please enter your PIN",Toast.LENGTH_LONG).show();
LayoutInflater inflaterPinVerificationDialog = this.getLayoutInflater();
final View inflatorPinVerificationDialog = inflaterPinVerificationDialog.inflate(R.layout.dialog_pin_verification, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
builder.setTitle("Session timed out. Please enter PIN");
builder.setView(inflatorPinVerificationDialog);
pinFromDialog = (EditText) inflatorPinVerificationDialog.findViewById(R.id.etDialogPin);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
String dialogPinValue = pinFromDialog.getText().toString();
String sharedPrefPinVal = loginData.getString("pin", "not found");
if (sharedPrefPinVal.equals(dialogPinValue)) {
Toast.makeText(getApplicationContext(), "login successful",
Toast.LENGTH_SHORT).show();
mainScreenActivity.lastLoggedIn = System.currentTimeMillis();
alertDialogPinVerification.dismiss();
} else {
Toast.makeText(getApplicationContext(),
"Incorrect pin - Please try again",
Toast.LENGTH_LONG).show();
}
}
});
builder.setNegativeButton("Forgot PIN", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alertDialogPinVerification = builder.create();
alertDialogPinVerification.show();
} else {
mainScreenActivity.lastLoggedIn = System.currentTimeMillis();
}
return super.dispatchTouchEvent(ev);
}
嗨周杰倫,感謝您的回覆,現在爲我工作。 目前它取消含有吐司消息的對話框爲不正確的引腳。 如果我不想在PIN碼錯誤時取消對話框,或者如何重新打開PIN碼輸入對話框,您能建議做什麼嗎? – BRDroid