Time display on ProgressBar in Android

Now I have created a progress bar and I want to allocate time for the progress bar (2min example) and the user should be able to see the time during the progress bar. How can we achieve this?

+1
source share
3 answers

You can update your ProgressBar using CountDownTimer

bar = (ProgressBar) findViewById(R.id.progress); bar.setProgress(total); int twoMin = 2 * 60 * 1000; // 2 minutes in milli seconds /** CountDownTimer starts with 2 minutes and every onTick is 1 second */ cdt = new CountDownTimer(twoMin, 1000) { public void onTick(long millisUntilFinished) { total = (int) ((dTotal / 120) * 100); bar.setProgress(total); } public void onFinish() { // DO something when 2 minutes is up } }.start(); 
+5
source

I suggest you use the progress dialog as well as use the progress bar. For customization, you can also use the run dialog in the process.

Please check the link. Also a link to the official Android blog. Link See Dialog for creating progress , and in this second example, a stream.

+1
source

Onkar ... AsyncTask can simultaneously complete a time-consuming task and report on progress made if a long-term task can be broken down into subtasks. AsyncTask uses generics to achieve its magic. The type of progress will be the middle type of the three “required formal type parameters” that make up <Params,Progress,Result> .

Jal

0
source

All Articles