简体   繁体   English

进度条未在android studio中更新

[英]progress bar is not updating in android studio

i'm using progress bar with countdown timer, everything is working fine except progress bar animation it not working in animation form, its just updating its state after the duration not in animation. 我正在使用带有倒数计时器的进度条,除了进度条动画它不以动画形式工作之外,其他所有东西都工作正常,它只是在持续时间之后不在动画中更新其状态。 Please somebody help me for this problem. 请有人帮我解决这个问题。

Here is my code 这是我的代码

   countDownTimer = new CountDownTimer(oneMin,1000) {
        @Override
        public void onTick(final long millisUntilFinished)
        {
         /*   long finishedSeconds = oneMin - millisUntilFinished;
            int total = (int) (((float)finishedSeconds / (float)oneMin) * 100.0);
            progressBar.setProgress(total);*/
            progressBar.setMax(100);
             progress = 1000*60/10;
progressBar.setProgress(progress);

            }

            @Override
        public void onFinish() {
            //t1.setText("");
            Toast.makeText(getActivity(), "your score", Toast.LENGTH_SHORT).show();
            dia1();

            progressBar.setProgress(0);
        }
    };

    tt2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if(ans.equals("1"))
            {
                countDownTimer.cancel();
                mp.start();


                Random r = new Random();
                i1 = r.nextInt(10 - 1) + 1;
                colorDetails(i1);
                i++;
                tt5.setText(String.valueOf("Score:"+i));
                countDownTimer.start();
            }
  • You setMax your progress bar 100 and then you setProgress 6000 !! setMax你的进度条100,然后你setProgress 6000! which is over the max value 超过最大值

  • Your progress bar will stop at the same progress every time you call onTick method because that method update the same value evey time you call it Read this to read some examples about progress bar 每次调用onTick方法时,进度条都会以相同的进度停止,因为该方法会更新您调用它的相同的值传达时间阅读本文以阅读一些有关进度条的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM