seekBar.setOnSeekBarChangeListener监听
自动重写3个方法:
onStopTrackingTouch://拖动后
onStartTrackingTouch://拖动前
onProgressChanged://拖动中
1. [代码]layout
01 | <? xml version = "1.0" encoding = "utf-8" ?> |
02 | < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" |
03 | android:orientation = "vertical" android:layout_width = "fill_parent" |
04 | android:layout_height = "fill_parent" > |
05 | < SeekBar android:id = "@+id/SeekBar01" android:layout_width = "fill_parent" |
06 | android:layout_height = "wrap_content" android:max = "100" |
07 | android:progress = "50" android:secondaryProgress = "100" ></ SeekBar > |
08 | < TextView android:id = "@+id/TextView1" android:layout_width = "fill_parent" |
09 | android:layout_height = "wrap_content" android:text = "" /> |
10 | < TextView android:id = "@+id/TextView2" android:layout_width = "fill_parent" |
11 | android:layout_height = "wrap_content" android:text = "" /> |
2. [代码]Test_SeekBar.java
01 | package com.Aina.Android; |
03 | import android.app.Activity; |
04 | import android.os.Bundle; |
05 | import android.widget.SeekBar; |
06 | import android.widget.TextView; |
08 | public class Test_SeekBar extends Activity implements SeekBar.OnSeekBarChangeListener{ |
09 | /** Called when the activity is first created. */ |
10 | private SeekBar seekBar; |
11 | private TextView textView1,textView2; |
13 | public void onCreate(Bundle savedInstanceState) { |
14 | super .onCreate(savedInstanceState); |
15 | setContentView(R.layout.main); |
16 | seekBar = (SeekBar) this .findViewById(R.id.SeekBar01); |
17 | textView1 = (TextView) this .findViewById(R.id.TextView1); |
18 | textView2 = (TextView) this .findViewById(R.id.TextView2); |
19 | seekBar.setOnSeekBarChangeListener( this ); //添加事件监听 |
23 | public void onProgressChanged(SeekBar seekBar, int progress, |
25 | this .textView1.setText( "当前值:" +progress); |
30 | public void onStartTrackingTouch(SeekBar seekBar) { |
31 | this .textView2.setText( "拖动中..." ); |
36 | public void onStopTrackingTouch(SeekBar seekBar) { |
37 | this .textView2.setText( "拖动完毕" ); |