Android SeekBar setOnSeekBarChangeListener

前端 未结 5 708
借酒劲吻你
借酒劲吻你 2020-12-03 09:58

I\'m wondering about the behavior of the android SeekBars OnSeekBarChangeListener. In particular, is the onProgressChanged-method notified only for the first and the last to

5条回答
  •  暖寄归人
    2020-12-03 10:02

    All answers are correct, but you need to convert a long big fat number into a timer first:

        public String toTimer(long milliseconds){
        String finalTimerString = "";
        String secondsString;
        // Convert total duration into time
        int hours = (int)( milliseconds / (1000*60*60));
        int minutes = (int)(milliseconds % (1000*60*60)) / (1000*60);
        int seconds = (int) ((milliseconds % (1000*60*60)) % (1000*60) / 1000);
        // Add hours if there
        if(hours > 0){
            finalTimerString = hours + ":";
        }
        // Prepending 0 to seconds if it is one digit
        if(seconds < 10){
            secondsString = "0" + seconds;
        }else{
            secondsString = "" + seconds;}
        finalTimerString = finalTimerString + minutes + ":" + secondsString;
        // return timer string
        return finalTimerString;
    }
    

    And this is how you use it:

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    textView.setText(String.format("%s", toTimer(progress)));        
    }
    

提交回复
热议问题