Android Progress Bar Listener

2019-07-23 17:02发布

Is there anyway to know when a progressbar has reached it maximum. Like a Listener then could plug into the ProgressBar and lets us know that the progress bar is at the maximum level ?

Kind Regards

2条回答
地球回转人心会变
2楼-- · 2019-07-23 17:25

There isn't a direct way to do this. A workaround could be to make a custom implementation of the ProgressBar and override the setProgress method:

public MyProgressBar extends ProgressBar
{
   @Override
   public void setProgress(int progress)
   {
       super.setProgress(progress);
       if(progress == this.getMax())
       {
           //Do stuff when progress is max
       }
   }
}
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-07-23 17:50

I think the cleanest way would be just adding this to your code:

 if (progressBar.getProgress() == progressBar.getMax()) {
     // do stuff you need
 }
查看更多
登录 后发表回答