android java 编程的异步特性有问题,如何在 onClick 处理程序中引发异常,或者带有警报对话框的方法如何返回值?我必须使用变量来传递结果吗?
public boolean validAccessCode = false;
// public boolean requestAccessCode(Activity mActivity) throws Exception {
public void requestAccessCode(Activity mActivity) throws Exception {
private EditText mPasswordView;
mPasswordView = new EditText(mActivity);
mPasswordView.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
mPasswordView.setTransformationMethod(new PasswordTransformationMethod());
AlertDialog.Builder alert = new AlertDialog.Builder(mActivity);
alert.setTitle("Enter access code");
alert.setView(mPasswordView);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String pw = mPasswordView.getText().toString();
if(pw.equals(accessCode))
{
validAccessCode = true;
return;
}
//throw new Exception("Invalid access code");
}
alert.show();
});