如何将CountDownTimer与浮点数一起使用

时间:2018-02-10 13:14:04

标签: android countdowntimer

如果可能的话,我想将milsec作为CountDownTimer的持续时间,这样做的方法是什么?

MuteBtn.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {

float seconds = Float.parseFloat(inputSeconds.getText().toString()); 
float milsec = seconds * 1000;

        new CountDownTimer(milsec, 1000) {
                public void onTick(long millisUntilFinished) {
                    inputSeconds.setText("seconds remaining: " + 
millisUntilFinished / 1000);
                    inputMinutes.setText("Minutes remaining:" + 
millisUntilFinished / 6000);
}

 public void onFinish() {

 inputSeconds.setText("Unmuted");strong text
 }
 }.start();
 }
 });

1 个答案:

答案 0 :(得分:0)

我使用

将浮动转换为long
long milsec = (long) (seconds * 1000);

现在可行了