How to Increment Seek bar value

别来无恙 提交于 2019-12-07 04:53:13

问题


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


回答1:


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"



回答2:


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.




回答3:


Try the following code.

seekBar.setProgress(YOUR_VALUE);


来源:https://stackoverflow.com/questions/16272053/how-to-increment-seek-bar-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!