How to show progress dialog in Android?

后端 未结 16 2589
予麋鹿
予麋鹿 2020-11-28 07:40

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?

相关标签:
16条回答
  • 2020-11-28 08:35

    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);
    }
    
    0 讨论(0)
  • 2020-11-28 08:36

    Simple coding in your activity like below:

    private ProgressDialog dialog = new ProgressDialog(YourActivity.this);    
    dialog.setMessage("please wait...");
    dialog.show();
    dialog.dismiss();
    
    0 讨论(0)
  • 2020-11-28 08:41

    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();
    
    0 讨论(0)
  • 2020-11-28 08:43

    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.

    0 讨论(0)
提交回复
热议问题