The progress of Android control developmentThis blog is mainly about the use of the Progress progress bar in Android development, the code is as follows:
Mainactivity.java:
Package com.example.progress;
Import Android.os.Bundle;
Import Android. R.integer;
Import android.app.Activity;
Import Android.view.Menu;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.ProgressBar;
public class Mainactivity extends Activity {
Private ProgressBar Firstbar = null;
Private ProgressBar Secendbar = null;
Private Button MyButton = null;
private int i = 0; Record the position of bar
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Firstbar = (ProgressBar) Findviewbyid (R.id.firstbar);
Secendbar = (ProgressBar) Findviewbyid (R.id.secendbar);
MyButton = (Button) Findviewbyid (R.id.mybutton);
Binding listeners
Mybutton.setonclicklistener (New Mybuutonsetonclicklistener ());
}
Class Mybuutonsetonclicklistener implements onclicklistener{
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
if (i = = 0) {
Set progress bar Visible
Firstbar.setvisibility (view.visible);
Secendbar.setvisibility (view.visible);
}
else if (i > 0 && i < Firstbar.getmax ()) {
Sets the current value of the progress bar's main progress
Firstbar.setprogress (i);
Sets the current value of the second progress of the progress bar
Firstbar.setsecondaryprogress (i + 10);
}
else{
Firstbar.setvisibility (View.gone);
Secendbar.setvisibility (View.gone);
Firstbar.setprogress (0);
Firstbar.setsecondaryprogress (0);
i =-10;
}
i + = 10;
}
}
@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;
}
}
layout file 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= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical"
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
Tools:context= ". Mainactivity ">
<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/hello_world"/>
<progressbar
Android:id= "@+id/firstbar"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:max= "200"
Android:visibility= "Gone"
Style= "? Android:attr/progressbarstylehorizontal"/>
<progressbar
Android:id= "@+id/secendbar"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:visibility= "Gone"
Style= "? Android:attr/progressbarstyle"/>
<button
Android:id= "@+id/mybutton"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "button"
Tools:ignore= "Hardcodedtext"/>
</LinearLayout>
the results shown are as follows:
When you click the button, the progress bar moves forward step by step
The progress of Android control development