Examples of how the progress bar is displayed on the web, there is no article on how to close the task at the end, refer to the other article after the experiment to show the complete set of progress bar Simple example is as follows:
Set up Android projects and other jobs are omitted, Google a bit.
The main activity is described below.
Progressbardemo.java
Package Com.lveyo.android.demo.progressbar;
Import android.app.Activity;
Import Android.app.ProgressDialog;
Import Android.os.Bundle;
Import Android.os.Handler;
Import Android.os.Message;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.TextView;
Public class Progressbardemo extends Activity {
private TextView statustextview;
private Button beginbtn;
private ProgressDialog ProgressDialog;
@Override
public void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Statustextview = (TextView) Findviewbyid (r.id.status);
beginbtn = (Button) Findviewbyid (R.ID.BEGINBTN);
Setlistener ();
}
/**
* Update UI with Handler
*/
private Handler Handler = new Handler () {
@Override
public void Handlemessage (Message msg) {
//Close ProgressDialog
progressdialog.dismiss ();
//Update UI
statustextview.settext ("Completed!");
}};
/**
* Click button Event Listener
*/
private void Setlistener () {
beginbtn.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
  &NBSP
//Display ProgressDialog
progressdialog = Progressdialog.show (Progressbardemo.this, "Loading ...", "Please wait ...", true, false);
//new Thread
new thread () {
@Override
public void Run () {
Methods that take time to calculate
Calculation.calculate (4);
Send a message to handler
Handler.sendemptymessage (0);
}}.start ();
}
});
}
}
Package Com.lveyo.android.demo.progressbar;
/**
* Schematic method
* @author Lveyo
*
*/
public class Calculation {
public static void calculate (int sleepseconds) {
try {
Thread.Sleep (sleepseconds * 1000);
} catch (Exception e) {
Todo:handle exception
}
}
}
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
>
<textview android:id= "@+id/status"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "@string/hello"
/>
<button android:id= "@+id/beginbtn"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "Begin"
/>
</LinearLayout>
In Android, we usually can't update the UI in a separate thread, but in the main thread, which is why we're using handler, and when handler receives the message, it puts it in the queue and waits for execution, which is usually done quickly.
A simple example of ProgressDialog in Android