Progress bar of Android-android learning journey)

Source: Internet
Author: User

Progress bar of Android-android learning journey)
ProgressBar Introduction

ProgressBar is a common Ui used to display the progress of complex operations and provide better user response. Use setProgress () incrementProgressBy () to set the progress and display progress to increase or decrease. A positive value indicates an increase, and a negative value indicates a decrease.

ProgressBar Style


ProgressBar

Code example layout code

      
           
            
             
       
      
     
    
       
       
        
     
    
   
  

      
          
       
        
    
   
  
Subject Code
package peng.liu.testview;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.widget.ProgressBar;public class MainActivity extends Activity {    private int[] data = new int[100];    int hasData = 0;    int status = 0;    ProgressBar bar,bar2;    Handler handler = new Handler(){        @Override        public void handleMessage(Message msg) {            if(msg.what == 0x123){                bar.setProgress(status);                bar2.setProgress(status);            }        }    };    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        bar = (ProgressBar) findViewById(R.id.bar);        bar2 = (ProgressBar) findViewById(R.id.bar2);        new Thread(){            @Override            public void run() {               if(status < 100){                   status = dowork();                   handler.sendEmptyMessage(0x123);               }            }        };    }    public int dowork(){        data[hasData++] = (int) (Math.random()*100);        try{            Thread.sleep(100);        }        catch (Exception e){            e.printStackTrace();        }        return hasData;    }}

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.