Code to show how to use progress Dialog in android
 
package com.example.chiprogress;

import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.util.Log;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

	private ProgressDialog progress;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		progress = new ProgressDialog(this);
	}
	public void open(View view){
		progress.setMessage("Downloading Music :) ");
		//progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		progress.setIndeterminate(true);
		progress.show();
		final int totalProgressTime = 100;
		final Thread t = new Thread(){
			@Override 
			public void run(){
				int jumpTime = 0;
				while(jumpTime < totalProgressTime){
					try {
						sleep(200);
						jumpTime += 15;
						progress.setProgress(jumpTime);
						progress.show();
						Log.d(getLocalClassName(), String.valueOf(jumpTime));
					}
					catch (InterruptedException e) {
						e.printStackTrace();
					}
					catch(Exception e){
						progress.dismiss();
						//progress.hide();
					}
				}
				//progress.hide();
				//Toast.makeText(getBaseContext(), "Work Completed", Toast.LENGTH_SHORT).show();
			}
		};
		t.start();
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	

}
share on whatapp
184 Views

Comments

223.176.133.122Good code
 
 
Private Policy   Terms of Service   4922