This example describes the ProgressBar usage in Android. Share to everyone for your reference, specific as follows:
ProgressBar is often used in Android, and the following examples illustrate how to use ProgressBar.
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.os.Handler;
Import Android.os.Message;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.ProgressBar;
public class A03activity extends activity {private ProgressBar rectangle,circle;
Private Button Showprogressbar;
Private final static int stop=0x10000;
Private final static int next=0x10001;
private int count=0; /** called the activity is a.
* * @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Rectangle= (ProgressBar) Findviewbyid (R.id.rectangle);
Circle= (ProgressBar) Findviewbyid (r.id.circle);
Showprogressbar= (Button) Findviewbyid (R.id.showprogressbar);
Rectangle.setindeterminate (FALSE);
Circle.setindeterminate (FALSE); Showprogressbar.setonclicklistener (New Onclicklistener () {@Override public void OnClick (ViewV) {//TODO auto-generated Method Stub rectangle.setvisibility (view.visible);
Circle.setvisibility (view.visible);
Rectangle.setmax (100);
Rectangle.setprogress (0);
Circle.setprogress (0); Thread T=new Thread (new Runnable () {@Override public void run () {//TODO auto-generated method stub for (int i
=0;i<20;i++) {try {count= (i+1) *5;
Thread.Sleep (1000);
if (count==19) {message msg=new message ();
Msg.what=stop;
Handler.sendmessage (msg);
Break
} else{message Msg=new message ();
Msg.what=next;
Handler.sendmessage (msg);
The catch (Interruptedexception e) {//TODO auto-generated catch block E.printstacktrace ();
}
}
}
});
T.start ();
}
});
Private Handler handler=new Handler () {@SuppressWarnings ("static-access") public void Handlemessage (msg) {
Switch (msg.what) {case STOP:rectangle.setVisibility (view.gone);
Circle.setvisibility (View.gone); Thread.CurrentThread (). interrupt ();
Break Case Next:if (!)
Thread.CurrentThread (). Interrupted ()) {rectangle.setprogress (count);
Circle.setprogress (count);
} break;
}
}
};
}
The
Res/layout/main.xml looks like this:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical " > <textview android:layout_width= "fill_parent" android:layout_height= wrap_content "android:text=" @str Ing/hello "/> <progressbar android:id= @+id/rectangle" android:layout_width= "Fill_parent" Android:lay out_height= "Wrap_content" style= "Android:attr/progressbarstylehorizontal" mce_style= "? android:attr/ Progressbarstylehorizontal "android:visibility=" Gone "/> <progressbar android:id=" @+id/circle "an Droid:layout_width= "Wrap_content" android:layout_height= "wrap_content" style= "? android:attr/ Progressbarstylelarge "mce_style=" "Android:attr/progressbarstylelarge" android:visibility= "Gone"/> & Lt Button android:id= "@+id/showprogressbar" android:layout_width="Wrap_content" android:layout_height= "Wrap_content" android:text= "show ProgressBar"/> </LinearLayout>
;
For more information about Android controls interested readers can view the site: "Android Control Usage Summary"
I hope this article will help you with the Android program.