How can I reset the Progressbar?

余生长醉 提交于 2019-12-11 18:13:53

问题


I just made a Countdowntimer and a Progressbar :

public void button1_onClick (View view) {
mCountDownTimer=new CountDownTimer(10000,1000) {

    @Override
    public void onTick(long millisUntilFinished) {
        Log.v("Log_tag", "Tick of Progress"+ i+ millisUntilFinished);
        i++;
        mProgressBar.setProgress(i);

    }

    @Override
    public void onFinish() {
        i++;
        mProgressBar.setProgress(i);
        game_end();
    }
};

 mCountDownTimer.start();
}
 public void button2_reset_onClick (View view) {
   mProgressBar.setProgress(0); }

It is also working but when I try to start it a second time I get no animation ? It counts until 10 but I cannot see it on the Progressbar... How can I reset the Progressbar properly ? I allready tried to make i = 0 but it doesnt helped


回答1:


mProgressBar.setProgress(i);
if(i == 0) {
mProgressBar.setProgress(100);  
}

if you want your counter automatically restarts when it reaches 0 uses this. otherwise do the opposite




回答2:


Where are you dismissing the progress bar. That internally calls the reset function of the progress bar and that will reset it to 0 for you.



来源:https://stackoverflow.com/questions/21971627/how-can-i-reset-the-progressbar

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