Progress bar Simple Demo

Source: Internet
Author: User

The layout is very simple.

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:orientation= "vertical"    tools:context= "com.example.loadprogressbardemo.MainActivity" >    <progressbar         android:id= "@+id/bar"        android:layout_width= "match_parent"        android:layout_height= " Wrap_content "         style="? android:attr/progressbarstylehorizontal "        />        <button        android:id= "@+id/btn"        android:layout_width= "wrap_content"        android:layout_height= "Wrap_content"        android: text= "Loading"/></linearlayout>

Logic code

Package Com.example.loadprogressbardemo;import Android.app.activity;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.view;import Android.view.View.OnClickListener; Import Android.widget.button;import Android.widget.progressbar;import Android.widget.toast;public class Mainactivity extends Activity {private Button btn;private ProgressBar bar; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); bar = (ProgressBar ) Findviewbyid (r.id.bar); btn = (Button) Findviewbyid (R.ID.BTN); Btn.setonclicklistener (new Buttonlistener ());} Class Buttonlistener implements onclicklistener{@Overridepublic void OnClick (View v) {//TODO auto-generated method Stubi F (v.getid () = = r.id.btn) {Thread t = new Loadthread (); T.start ();}}} Class Loadthread extends Thread{public void Run () {for (int i=0;i<100;i++) {try {Thread.Sleep]} catch ( Interruptedexception e) {//TODO auto-generated catchBlocke.printstacktrace ();} Bar.setprogress (Bar.getprogress () +1);}}}





Progress bar Simple Demo

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.