How to show progress dialog in Android?

后端 未结 16 2592
予麋鹿
予麋鹿 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:21
      final ProgressDialog loadingDialog = ProgressDialog.show(context,
         "Fetching BloodBank List","Please wait...",false,false);  // for  showing the 
        // dialog  where context is the current context, next field is title followed by
        // message to be shown to the user and in the end intermediate field
        loadingDialog.dismiss();// for dismissing the dialog 
    

    for more info Android - What is difference between progressDialog.show() and ProgressDialog.show()?

    0 讨论(0)
  • 2020-11-28 08:21

    Simple Way :

    ProgressDialog pDialog = new ProgressDialog(MainActivity.this); //Your Activity.this
    pDialog.setMessage("Loading...!");
    pDialog.setCancelable(false);
    pDialog.show();
    
    0 讨论(0)
  • 2020-11-28 08:22
    ProgressDialog pd = new ProgressDialog(yourActivity.this);
    pd.setMessage("loading");
    pd.show();
    

    And that's all you need.

    0 讨论(0)
  • 2020-11-28 08:26

    Step 1:Creata a XML File

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
    
        <Button
            android:id="@+id/btnProgress"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Progress Dialog"/>
    </LinearLayout>
    

    Step 2:Create a SampleActivity.java

    package com.scancode.acutesoft.telephonymanagerapp;
    
    
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class SampleActivity extends Activity implements View.OnClickListener {
        Button btnProgress;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            btnProgress = (Button) findViewById(R.id.btnProgress);
            btnProgress.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
    
            final ProgressDialog progressDialog = new ProgressDialog(SampleActivity.this);
            progressDialog.setMessage("Please wait data is Processing");
            progressDialog.show();
    
    //        After 2 Seconds i dismiss progress Dialog
    
            new Thread(){
                @Override
                public void run() {
                    super.run();
                    try {
                        Thread.sleep(2000);
                        if (progressDialog.isShowing())
                            progressDialog.dismiss();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }
    
    0 讨论(0)
  • 2020-11-28 08:27

    To use ProgressDialog use the below code

    ProgressDialog progressdialog = new ProgressDialog(getApplicationContext());
    progressdialog.setMessage("Please Wait....");
    

    To start the ProgressDialog use

    progressdialog.show();
    

    progressdialog.setCancelable(false); is used so that ProgressDialog cannot be cancelled until the work is done.

    To stop the ProgressDialog use this code (when your work is finished):

    progressdialog.dismiss();`
    
    0 讨论(0)
  • 2020-11-28 08:34
    ProgressDialog pd = new ProgressDialog(yourActivity.this);
    pd.show();
    
    0 讨论(0)
提交回复
热议问题