Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Increment Seek bar value

I want to create seekbar that is divided into 5 section poor , below Average Average and Excellent , for every step i want increment like this seekbar Default=0 max value = 100;

i want seek bar values like this :0,25,50,75,100

how can i achieve this.

Thanks

like image 606
user1737884 Avatar asked Apr 29 '13 05:04

user1737884


People also ask

How do you set a seek bar value?

In Order to the seekBar to Change while you are in the Activity you need to Call the method setProgress(), and pass it a boolean animate value. I think the problem is related to setting the progress of the seek bar something greater than its max value.

What is a seek bar in Android?

android.widget.SeekBar. A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.


2 Answers

You have to just update the onProgressChanged method as follows.

int yourStep = 25;
public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
progress = ((int)Math.round(progress/yourStep ))*yourStep;
seekBar.setProgress(progress);
textview.setText(progress + "");

}

Hope its help

UPD

I think in your xml you set android:max="100" for your SeekBar. But you need to set android:max="101", because between 0 and 100 = 101 point's.

just replace

android:max="100"

for

android:max="101"
like image 191
jimpanzer Avatar answered Sep 19 '22 03:09

jimpanzer


Try this:

seekBar.setProgress(4);

This will give the values, 0, 1, 2, 3, 4. You don't need to be playing about with onProgressChanged, simply multiply by 25 and you have the values 0, 25, 50, 75, 100.

like image 41
Dan Bray Avatar answered Sep 18 '22 03:09

Dan Bray