I'm trying to present the user with a login dialog (custom dialog with custom view), and when then click "Login", i'm trying to show a ProgressDialog, then close it once the login has completed.
Problem is i can't get the ProgressDialog to show up.
Here's my code:
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;
}
This code is in a Presenter, which get's passed the main activity instance. Just to keep the UI logic seperate.
In the main activity (onCreate
), i do this:
showDialog(DIALOG_SIGNUP);
Then i override onCreateDialog
method:
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DIALOG_SIGNUP: {
dialog = presenter.getLoginSignupDialog();
break;
}
}
return dialog;
}
The other dialog (custom login one) gets shown fine, everything works, closes, etc. But i can't get the ProgressDialog to show.
What am i doing wrong?