android中ProgressBar的使用SeekBar的使用和RatingBar的使用

MainActivity.java文件代码

成都创新互联是一家集网站建设,花都企业网站建设,花都品牌网站建设,网站定制,花都网站建设报价,网络营销,网络优化,花都网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

package com.example.android_pickers2;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast;
public class MainActivity extends Activity {
    Button button ;
    ProgressBar bar;
    SeekBar seekBar;
    RatingBar ratingBar;
             
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) this.findViewById(R.id.button1);
        bar = (ProgressBar) this.findViewById(R.id.progressBar1);
        bar.setMax(100);
        button.setOnClickListener(new OnClickListener() {
                     
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                MyTask task = new MyTask();
                task.execute();
            }
        });
        //SeekBar的使用
        seekBar = (SeekBar) this.findViewById(R.id.seekBar1);
        seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                     
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }
                     
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
                         
            }
                     
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                Toast.makeText(MainActivity.this, "->>"+progress, 1).show();
                System.out.println("-->"+progress);
                // TODO Auto-generated method stub
                         
            }
        });
        //RatingBar的使用
        ratingBar = (RatingBar) this.findViewById(R.id.ratingBar1);
        ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
                     
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating,
                    boolean fromUser) {
                // TODO Auto-generated method stub
                Toast.makeText(MainActivity.this, "->"+rating, 1).show();
                         
            }
        });
    }
             
    /*
     * 定义一个类继承AsyncTask类,动态改变ProgressBar
     */
    class MyTask extends AsyncTask{
        @Override
        protected void onProgressUpdate(Integer... values) {
            // TODO Auto-generated method stub
            super.onProgressUpdate(values);
            //更新bar
            bar.setProgress(values[0]+20);
        }
                 
        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub
                     
            int i=1;
            while(i<=100){
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
                publishProgress(i);
                i++;
            }
            return null;
        }
                 
    }
    @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;
    }
}

activity_main.xml代码:


    

当前标题:android中ProgressBar的使用SeekBar的使用和RatingBar的使用
本文路径:http://azwzsj.com/article/jhhhog.html