Last active
April 2, 2021 22:10
-
-
Save NarendraDodiya/c3049b666747227ed71d to your computer and use it in GitHub Desktop.
seekbar with step value and min max or range values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tyrantgit.sample; | |
import android.view.View; | |
import android.widget.SeekBar; | |
/** | |
* Created by narendra on 30/9/15. | |
*/ | |
public class StepValueSeekbar { | |
private void createStepValueSeekbar(View v, final int MIN, final int MAX, final int STEP, int currentValue) { | |
SeekBar seekBar = (SeekBar) v.findViewById(R.id.seekbar); | |
seekBar.setMax(100); | |
seekBar.setProgress(calculateProgress(currentValue, MIN, MAX, STEP)); | |
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | |
@Override | |
public void onStopTrackingTouch(SeekBar seekBar) { | |
} | |
@Override | |
public void onStartTrackingTouch(SeekBar seekBar) { | |
} | |
@Override | |
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |
double value = Math.round((progress * (MAX - MIN)) / 100); | |
int displayValue = (((int) value + MIN) / STEP) * STEP; | |
} | |
}); | |
} | |
private int calculateProgress(int value, int MIN, int MAX, int STEP) { | |
return (100 * (value - MIN)) / (MAX - MIN); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment