不能将用户输入的代码作为返回值传递给 Callable。
登录主持人:
public void login(String username, String password) {
model.login(username, password,
new IGClient.Builder.LoginHandler() {
@Override
public LoginResponse accept(IGClient client, LoginResponse t) {
return IGChallengeUtils.resolveTwoFactor(client, t, new Callable<String>() {
@Override
public String call() throws Exception {
getView().showDialog(); // method from activity
return null; // here must be code that user entered
}
});
}
}
登录活动:
public void showDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = getLayoutInflater().inflate(R.layout.request_code_dialog, null);
builder.setMessage("Write code from SMS");
builder.setView(view)
.setPositiveButton(R.string.okey_text,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
String code = ((EditText) view.findViewById(R.id.request_code_dialog_edittext_code)).getText().toString();
// ??? how to pass this code to Callable ???
}
}
);
AlertDialog alert = builder.create();
alert.show();
}
我试图通过 Callback 传递代码,但是如果我使用它,我无法将 Callback 的值设置为 Callable 的返回值。需要显示一个输入短信验证码的窗口,并在用户点击后将此验证码作为返回值传递给用户。