【发布时间】:2014-01-27 17:35:06
【问题描述】:
我有一个自定义 AlertDialog,其中包含 PIN 的 EditText。 OnClick 的肯定按钮使用 SharedPreferences 检查editText 中的 PIN。如果匹配,我想关闭对话框,否则它应该保持打开状态。 当 PIN 正确时,对话框关闭并重新出现,我不希望它重新出现。 提前感谢您的帮助。
@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);
}
【问题讨论】:
标签: android android-alertdialog