I want to show ProgressDialog
when I click on Login button and it takes time to move to another page. How can I do this?
ProgressDialog is deprecated since API 26
still you can use this:
public void button_click(View view)
{
final ProgressDialog progressDialog = ProgressDialog.show(Login.this,"Please Wait","Processing...",true);
}
Simple coding in your activity
like below:
private ProgressDialog dialog = new ProgressDialog(YourActivity.this);
dialog.setMessage("please wait...");
dialog.show();
dialog.dismiss();
Declare your progress dialog:
ProgressDialog progressDialog;
To start the progress dialog:
progressDialog = ProgressDialog.show(this, "","Please Wait...", true);
To dismiss the Progress Dialog :
progressDialog.dismiss();
Point one you should remember when it comes to Progress dialog is that you should run it in a separate thread. If you run it in your UI thread you'll see no dialog.
If you are new to Android Threading then you should learn about AsyncTask. Which helps you to implement a painless Threads.
sample code
private class CheckTypesTask extends AsyncTask<Void, Void, Void>{
ProgressDialog asyncDialog = new ProgressDialog(IncidentFormActivity.this);
String typeStatus;
@Override
protected void onPreExecute() {
//set message of the dialog
asyncDialog.setMessage(getString(R.string.loadingtype));
//show dialog
asyncDialog.show();
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg0) {
//don't touch dialog here it'll break the application
//do some lengthy stuff like calling login webservice
return null;
}
@Override
protected void onPostExecute(Void result) {
//hide the dialog
asyncDialog.dismiss();
super.onPostExecute(result);
}
}
Good luck.