Android control development-progress SS
Android control development-progress SSThis blog post describes how to use the 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 bar position
@ 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 );
// Bind the listener
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 visibility
FirstBar. setVisibility (View. VISIBLE );
SecendBar. setVisibility (View. VISIBLE );
}
Else if (I> 0 & I <firstBar. getMax ()){
// Set the current value of the main progress of the progress bar
FirstBar. setProgress (I );
// Set 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:
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>
Android: layout_width = wrap_content
Android: layout_height = wrap_content
Android: text = @ string/hello_world/>
Android: id = @ + id/firstBar
Android: layout_width = fill_parent
Android: layout_height = wrap_content
Android: max = 200
Android: visibility = gone
Style =? Android: attr/progressBarStyleHorizontal/>
Android: id = @ + id/secendBar
Android: layout_width = wrap_content
Android: layout_height = wrap_content
Android: visibility = gone
Style =? Android: attr/progressBarStyle/>
Android: id = @ + id/myButton
Android: layout_width = wrap_content
Android: layout_height = wrap_content
Android: text = button
Tools: ignore = HardcodedText/>