ユーザーにログイン ダイアログ (カスタム ビューのカスタム ダイアログ) を表示しようとしています。[ログイン] をクリックすると、ProgressDialog を表示し、ログインが完了したら閉じます。
問題は、ProgressDialog を表示できないことです。
これが私のコードです:
private final MyActivity activity;
public MyPresenter(MyActivity activity) {
this.activity = activity;
}
public Dialog getLoginSignupDialog() {
final Dialog dialog = new Dialog(activity);
dialog.setContentView(R.layout.dialog_signup);
dialog.setTitle("Login");
final TextView email = (TextView)dialog.findViewById(R.id.textViewEmail);
final TextView password = (TextView)dialog.findViewById(R.id.textViewPassword);
Button signupButton = (Button)dialog.findViewById(R.id.buttonSignup);
signupButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ProgressDialog progressDialog = null;
try {
progressDialog = ProgressDialog.show(activity, "", "Signing up...",false);
activity.signup(email.getText().toString(), password.getText().toString());
progressDialog.dismiss();
dialog.dismiss();
} catch (ParseException e) {
if (progressDialog != null) progressDialog.dismiss();
Toast.makeText(activity, "Sorry, an error occured.", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
});
return dialog;
}
このコードはプレゼンターにあり、メイン アクティビティ インスタンスが渡されます。UIロジックを分離しておくためだけに。
主なアクティビティ ( onCreate
) では、次のことを行います。
showDialog(DIALOG_SIGNUP);
onCreateDialog
次に、メソッドをオーバーライドします。
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DIALOG_SIGNUP: {
dialog = presenter.getLoginSignupDialog();
break;
}
}
return dialog;
}
もう 1 つのダイアログ (カスタム ログイン 1 つ) は正常に表示され、すべてが機能し、閉じます。しかし、ProgressDialog を表示できません。
私は何を間違っていますか?