MainActivity.java文件代碼
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),花都企業(yè)網(wǎng)站建設(shè),花都品牌網(wǎng)站建設(shè),網(wǎng)站定制,花都網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,花都網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
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類,動態(tài)改變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代碼: