Android control development-progress SS

Source: Internet
Author: User

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/>




 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.