The function of the project is to achieve the progress bar display, press the following button to increase the progress bar 10%
The following code is the code in Mainactivity.java
PackageCom.example.progressbar;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.ProgressBar; Public classMainactivityextendsActivity {//declaration Limit PrivateProgressBar Firstbar =NULL; PrivateProgressBar Secondbar =NULL; PrivateButton MyButton =NULL; Private inti = 0; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //gets the object that represents the control based on the control's IDFirstbar =(ProgressBar) Findviewbyid (R.id.firstbar); Secondbar=(ProgressBar) Findviewbyid (R.id.secondbar); MyButton=(Button) Findviewbyid (R.id.mybutton); Mybutton.setonclicklistener (NewButtonlistener ()); System.out.print (Firstbar.getmax ()); } classButtonlistenerImplementsonclicklistener{@Override Public voidOnClick (View v) {//TODO auto-generated Method Stub if(i = = 0) { //to set a progress bar in a visible statefirstbar.setvisibility (view.visible); Secondbar.setvisibility (view.visible); } Else if(I <Firstbar.getmax ()) { //set the current value of the main progress barfirstbar.setprogress (i); //set the current value of the second progress barFirstbar.setsecondaryprogress (i + 10)); //because the default progress bar cannot display the status of the//secondbar.setprogress (i); } Else { //Setting the progress bar in an invisible statefirstbar.setvisibility (View.gone); Secondbar.setvisibility (View.gone); } I= i + 10; } }}
The following code is the code in Activity_main.xml
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/linearlayout1"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "Vertical"Tools:context= "${relativepackage}.${activityclass}" > <TextView android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "@string/hello_world"/> <ProgressBar Android:id= "@+id/firstbar"style= "? Android:attr/progressbarstylehorizontal"Android:layout_width= "200DP"Android:layout_height= "Wrap_content"android:visibility= "Gone"/> <ProgressBar Android:id= "@+id/secondbar"style= "? Android:attr/progressbarstyle"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:visibility= "Gone"Android:max= "/>" <Button Android:id= "@+id/mybutton"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Begin"/> </LinearLayout>
Android Learning Note--progressbar