Android : Min value in SeekBar
Mardi, janvier 25th, 2011I found no way to set a min value for Android SeekBar so I decided to do it myself.
The result is not really as many may expect but I think this is suitable enough for many usage.
I simply relied on the secondProgress property and tried to make it still.
Then on the Activity that handles the view, the
view.xml :
<< SeekBar android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/slider"
android:max="64"
android:secondaryProgress="8"/>
Activity :
public class Settings extends Activity implements OnSeekBarChangeListener {
private SeekBar sb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
sb = (SeekBar) findViewById(R.id.slider);
sb.setOnSeekBarChangeListener(this);
}
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
processProgressMin();
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
processProgressMin();
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
processProgressMin();
}
private void processProgressMin() {
if (sb.getProgress() < sb.getSecondaryProgress())
sb.setProgress(sb.getSecondaryProgress());
}
}
Here it is!
