Showing Time On Progressbar In Android
Now,i have created progress bar and i want to allot time for progress bar(Ex. 2min) and user must able to see time while running progress bar. how we can achieve this?
Solution 1:
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) {
publicvoidonTick(long millisUntilFinished) {
total = (int) ((dTotal / 120) * 100);
bar.setProgress(total);
}
publicvoidonFinish() {
// DO something when 2 minutes is up
}
}.start();
Solution 2:
I suggest you to use progress dialog rather using progress bar.Again for setting it is also possible using thread in progress dialog.
Please check this link.Also link from official android blog. Link Please see Creating Progress Dialog & in that second example using thread.
Solution 3:
Onkar... AsyncTask can both host the time intensive task and report progress, IF the time intensive task can be broken up into sub-tasks. AsyncTask uses generics to accomplish its magic. The progress type would be the middle type of the three "required formal type parameters" being <Params,Progress,Result>
.
JAL
Post a Comment for "Showing Time On Progressbar In Android"