How to use Progress Dialog in Android

Using of Progress Dialog

progress bar are used to show progress of task e.g. downloading file,analyzing status of work etc.

//ProgressDialog progress = new ProgressDialog(this);

Now you can set some properties of this dialog.

progressDialog = new ProgressDialog(this);
                progressDialog.setMessage("Downloading...");
                progressDialog.setTitle("Your Title");
                progressDialog.setCancelable(true);
                progressDialog.setIndeterminate(true);
                progressDialog.show();	

activity_main.xml

<Button
       android:layout_width="200dp"
       android:layout_marginLeft="60dp"
       android:text="Progress Dialog"
       android:id="@+id/button"
       android:layout_height="wrap_content"
       android:layout_marginTop="170dp"
       android:layout_alignParentTop="true"
       />	

MainActivity.java

import android.app.ProgressDialog;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;


public class MainActivity extends ActionBarActivity {
    private ProgressDialog progressDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //   progressDialog=new ProgressDialog(MainActivity.this);
        Button btn_start_progress = (Button) findViewById(R.id.button);
        btn_start_progress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                progressDialog = new ProgressDialog(MainActivity.this);
                progressDialog.setMessage("Downloading...");
                progressDialog.setTitle("Your Title");
                progressDialog.setCancelable(true);
                progressDialog.setIndeterminate(true);
                progressDialog.show();
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}			

How to use Progress Dialog in Android

Related Posts

Leave a comment

Hey, so you decided to leave a comment! That's great. Just fill in the required fields and hit submit. Note that your comment will need to be reviewed before its published.