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:gravity="center_horizontal"
android:orientation="vertical" >
<SeekBar
android:id="@+id/sb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="30"
android:max="100"/>
<TextView
android:id="@+id/show"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
java对SeekBar监听
package com.example.assembly;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView showTv;
private String str = "";
private SeekBar sb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showTv = (TextView) findViewById(R.id.show);
sb=(SeekBar) findViewById(R.id.sb);
showTv.setText(sb.getProgress()+"");
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
//松开滑杆
str="松开滑杆"+sb.getProgress();
showTv.setText(str);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// 按住滑杆
str="按住滑杆"+sb.getProgress();
showTv.setText(str);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// 滑动滑杆
str="当前进度为:"+progress;
showTv.setText(str);
}
});
}
}
效果图: