package com.example.progressbar; import java.io.IOException; import android.os.Bundle; import android.app.Activity; import android.app.ProgressDialog; import android.view.Menu; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { private Button btn; private ProgressDialog pg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn=(Button)findViewById(R.id.b1); btn.setOnClickListener(new Button.OnClickListener() { public void onClick(View view) { final CharSequence Body="Please wait for a moment"; final CharSequence Title="Progress Bar"; pg=ProgressDialog.show(MainActivity.this, Title, Body); new Thread() { public void run() { try { sleep(3000); } catch(Exception e) { e.printStackTrace(); } finally { pg.dismiss(); } } }.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; } }