How to set seekbar min and max value

前端 未结 14 901
栀梦
栀梦 2020-11-28 09:17

I have a seekbar and trying to set the value from 60 to 180 for one and 40 to 190 for the second one in step of 1.

sb1 = (SeekBar) findViewById(R.id.progress         


        
14条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 09:57

    Min-value will always start at zero and its nothing you can do about it. But you can change its value when user start scrolling it around.

    Here I set the max-value as 64. This calculations are simple: I want the user to pick a time from 15min to 16 hours, and he picks one of every 15min to 16 hours, clear? I know, very simple :)

        SeekBar seekBar = (SeekBar) dialog.findViewById(R.id.seekBar);
        seekBar.setMax(64);
    
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            float b;
    
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                float des = (float) progress / 4;
                b = des;
                hours.setText(des + " hours");
            }
    
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
    
    
            }
    
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                hoursSelected = b;
            }
        });
    

提交回复
热议问题