直接上代码。
package t.s.b;
import java.text.DecimalFormat;
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
public class TestSeekBar extends Activity implements
SeekBar.OnSeekBarChangeListener {
SeekBar mSeekBar;
TextView mProgressText;
TextView mTrackingText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSeekBar = (SeekBar) findViewById(R.id.seek);
mSeekBar.setOnSeekBarChangeListener(this);
mSeekBar.setMax(1000);
mProgressText = (TextView) findViewById(R.id.progress);
mTrackingText = (TextView) findViewById(R.id.tracking);
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromTouch) {
double putvalue = progress * 0.1;
DecimalFormat df = new DecimalFormat("#0.0");
double fp = new Double(df.format(putvalue));
mProgressText.setText(fp + "% " + getString(R.string.seekbar_from_touch)
+ "=" + fromTouch);
}
public void onStartTrackingTouch(SeekBar seekBar) {
mTrackingText.setText(getString(R.string.seekbar_tracking_on));
}
public void onStopTrackingTouch(SeekBar seekBar) {
mTrackingText.setText(getString(R.string.seekbar_tracking_off));
}
}