Use of the progress bar Control

Source: Internet
Author: User
1   Package  Com. example. helloworld;  2   3   Import  Android. App. activity;  4   Import  Android. OS. Bundle;  5   Import  Android. View. view;  6   Import  Android. View. View. onclicklistener; 7   Import  Android. widget. Button;  8   Import  Android. widget. progressbar;  9   10   /**  11   * Common controls: Three progressbar listview  12   *  13   *  @ Author  David 14   *  15    */  16   Public   Class Tenlessondemo1 Extends  Activity {  17   18       Private Progressbar firstbar = Null  ;  19       Private Progressbar secondbar =Null  ;  20       Private Button mybutton = Null  ;  21       Private   Int I = 0 ;  22   23   @ Override  24       Protected   Void Oncreate (bundle savedinstancestate ){  25           //  Todo auto-generated method stub  26           Super  . Oncreate (savedinstancestate );  27           This  . Setcontentview (R. layout. tenone );  28 Firstbar = (Progressbar) findviewbyid (R. Id. firstbar );  29 Secondbar =(Progressbar) findviewbyid (R. Id. secondbar );  30 Mybutton = (Button) findviewbyid (R. Id. mybutton );  31 Mybutton. setonclicklistener ( New  Buttonlistener ());  32   System. Out. println (firstbar. getmax ());  33   }  34   35       Class ButtonlistenerImplements  Onclicklistener {  36   37           Public   Void  Onclick (view arg0 ){  38               //  Todo auto-generated method stub  39               If (I = 0 ){  40 Firstbar. setvisibility (view. Visible ); // Set the progress bar to visible  41   Secondbar. setvisibility (view. Visible );  42 } Else   If (I < Firstbar. getmax ()){  43 Firstbar. setprogress (I ); //  Set the current value of the progress bar  44 Firstbar. setsecondaryprogress (I + 10 ); //  Second color of the progress bar 45 Secondbar. setprogress (I ); //  This does not work, because the default progress bar cannot be displayed.  46 } Else  {  47   Firstbar. setvisibility (view. Gone );  48 Secondbar. setvisibility (view. Gone ); //  Set the progress bar to invisible  49   50   } 51 I = I + 10 ;  52   }  53   }  54 }

 

 1   <  Linearlayout  Xmlns: Android  = "Http://schemas.android.com/apk/res/android"  2   Android: layout_width  = "Fill_parent" 3   Android: layout_height  = "Fill_parent"  4   Android: Orientation  = "Vertical"   >  5   6       <  Textview  7           Android: ID  = "@ + ID/textview1"  8   Android: layout_width = "Fill_parent"  9   Android: layout_height  = "Wrap_content"  10   Android: Text  = "Hello"   />  11   12       <  Progressbar  13           Android: ID  = "@ + ID/firstbar"  14  Style  = "? Android: ATTR/progressbarstylehorizontal"  15   Android: layout_width  = "200dp"  16   Android: layout_height  = "Wrap_content"  17   Android: Max  = "200"  18   Android: visibility  = "Gone"   /> 19   20       <  Progressbar  21           Android: ID  = "@ + ID/secondbar"  22   Style  = "? Android: ATTR/progressbarstyle"  23   Android: layout_width  = "Wrap_content"  24   Android: layout_height = "Wrap_content"  25   Android: visibility  = "Gone"   />  26   27       <  Button  28           Android: ID  = "@ + ID/mybutton"  29   Android: layout_width  = "Wrap_content"  30  Android: layout_height  = "Wrap_content"  31   Android: Text  = "OK"   />  32   33   </  Linearlayout  > 

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.