.java代码:
package com.example.day6;
import android.app.Activity;
import android.os.Bundle;
import android.view.View.OnCreateContextMenuListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
public class seek extends Activity implements OnSeekBarChangeListener{
private TextView one;
private TextView two;
private SeekBar sone;
private SeekBar stwo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seek);
one = (TextView) findViewById(R.id.one);
two = (TextView) findViewById(R.id.two);
sone = (SeekBar) findViewById(R.id.sone);
stwo = (SeekBar) findViewById(R.id.stwo);
sone.setOnSeekBarChangeListener(this);
stwo.setOnSeekBarChangeListener(this);
}
// 进度值改变回调方法
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if(seekBar.getId()==R.id.sone){
one.setText("当前位置:"+progress);
}else{
two.setText("当前位置:"+progress);
}
}
// 开始拖动回调方法
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
if(seekBar.getId()==R.id.sone){
one.setText("开始拖动");
}else{
two.setText("开始拖动");
}
}
// 停止拖动回调方法
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if(seekBar.getId()==R.id.sone){
one.setText("停止拖动");
}else{
two.setText("停止拖动");
}
}
}
.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/one"
android:text="谢柳"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/two"
android:text="谢柳"/>
<SeekBar
android:id="@+id/sone"
android:progress="40"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<SeekBar
android:id="@+id/stwo"
android:progress="50"
android:secondaryProgress="80"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>