Android Progress bar Component ProgressBar

Source: Internet
Author: User

First is the Main.xml file

The code is as follows:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:orientation=" vertical "android:layout_width=" fill_parent "Android:layout_heigh t= "Fill_parent" ><progressbar android:id= "@+id/myprobara" style= "? Android:attr/progressbarstyle" Android:v Isibility= "Gone" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content"/><ProgressBar and Roid:id= "@+id/myprobarb" style= "Android:attr/progressbarstylehorizontal" android:visibility= "Gone" android:layou T_width= "Fill_parent" android:layout_height= "wrap_content"/><progressbar android:id= "@+id/myprobarC" style = "Android:attr/progressbarstylehorizontal" android:visibility= "Gone" android:max= "+" android:progress= "0" a Ndroid:layout_width= "Fill_parent" android:layout_height= "wrap_content"/><progressbar android:id= "@+id/ Myprobard "android:visibility=" Gone "Android:max= "android:progress=" "android:secondaryprogress=" "style=" "Android:attr/progressbarstylelarge" Androi D:layout_width= "Fill_parent" android:layout_height= "wrap_content"/><progressbar android:id= "@+id/myprobarE "Android:visibility=" Gone "android:max=" "android:progress=" "android:secondaryprogress=" "style="? Android:attr/progressbarstylesmall "android:layout_width=" fill_parent "android:layout_height=" Wrap_content "/> <button android:id= "@+id/mybut" android:text= "Show progress bar" Android:layout_width= "Wrap_content" android:layout_he  ight= "Wrap_content"/></linearlayout>

Then write the Activity.java class

The code is as follows:

Package Com.example.myfirstproject;import Java.sql.date;import Java.text.simpledateformat;import Java.util.arraylist;import Java.util.list;import Java.util.timer;import Java.util.timertask;import Android.os.bundle;import Android.os.handler;import Android.os.looper;import Android.os.message;import Android.app.activity;import Android.content.pm.activityinfo;import Android.content.res.configuration;import Android.view.menu;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.ViewGroup Import android.widget.*;p ublic class Mainactivity extends Activity {private ProgressBar Myprobara,myprobarb,myprobarc    , Myprobard,myprobare;private Button mybut;protected static final int STOP = 1;protected static final int CONTINUE = 2;        public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        This.myprobara = (ProgressBar) This.findviewbyid (R.id.myprobara); This.myprobarb = (ProgRessbar) This.findviewbyid (R.id.myprobarb);        This.myprobarc = (ProgressBar) This.findviewbyid (R.ID.MYPROBARC);        This.myprobard = (ProgressBar) This.findviewbyid (R.id.myprobard);        This.myprobare = (ProgressBar) This.findviewbyid (R.id.myprobare);        This.mybut = (Button) This.findviewbyid (r.id.mybut);        This.myprobarA.setIndeterminate (FALSE);        This.myprobarB.setIndeterminate (FALSE);        This.myprobarC.setIndeterminate (TRUE);        This.myprobarD.setIndeterminate (FALSE);        This.myprobarE.setIndeterminate (FALSE);    This.mybut.setOnClickListener (New Onclicklistenerlmpl ()); } Private class Onclicklistenerlmpl implements onclicklistener{public void OnClick (view view) {mainactivity.    This.myprobarB.setSecondaryProgress (0);    MainActivity.this.myprobarA.setVisibility (view.visible);    MainActivity.this.myprobarB.setVisibility (view.visible);    MainActivity.this.myprobarC.setVisibility (view.visible); MainActivity.this.myprobarD.setVisiBility (view.visible);    MainActivity.this.myprobarE.setVisibility (view.visible);    MainActivity.this.myprobarA.setMax (120);    MainActivity.this.myprobarB.setMax (120);    MainActivity.this.myprobarA.setProgress (0);    MainActivity.this.myprobarB.setProgress (0);    New Thread (New Runnable () {public void run () {int count = 0;    for (int i = 0;i < 10;i++) {try{count = (i+1) *20;    Thread.Sleep (500);    if (i==6) {Message m = new Message ();    M.what = Mainactivity.stop;    MainActivity.this.myMessageHandler.sendMessage (m);    Break    }else{Message m = new Message ();    M.ARG1 = count;    M.what = mainactivity.continue;    MainActivity.this.myMessageHandler.sendMessage (m);    }}catch (Exception ex) {ex.printstacktrace ();    }}}). Start (); }} private Handler Mymessagehandler = new Handler () {public void Handlemessage (Message msg) {switch (msg.what)    {Case MainActivity.STOP:myprobarA.setVisibility (view.gone); Myprobarb.setviSibility (View.gone);    Myprobarc.setvisibility (View.gone);    Myprobard.setvisibility (View.gone);    Myprobare.setvisibility (View.gone);    Thread.CurrentThread (). interrupt ();    Break Case MainActivity.CONTINUE:if (!    Thread.CurrentThread (). isinterrupted ()) {myprobara.setprogress (MSG.ARG1);    Myprobarb.setprogress (MSG.ARG1);    Myprobarc.setprogress (MSG.ARG1);    Myprobard.setprogress (MSG.ARG1);    Myprobare.setprogress (MSG.ARG1);    } break; }    }    };}

Operating effect:

Android Progress bar Component ProgressBar

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.