Книга: Beginning Android

Making Progress

Making Progress

If you need to be doing something for a long period of time, you owe it to your users to do two things:

• Use a background thread, which will be covered in Chapter 15

• Keep them apprised of your progress, or else they think your activity has wandered away and will never come back

The typical approach to keeping users informed of progress is some form of progress bar or “throbber” (think the animated graphic towards the upper-right corner of many Web browsers). Android supports this through the ProgressBar widget.

A ProgressBar keeps track of progress, defined as an integer, with 0 indicating no progress has been made. You can define the maximum end of the range — what value indicates progress is complete — via setMax(). By default, a ProgressBar starts with a progress of 0, though you can start from some other position via setProgress().

If you prefer your progress bar to be indeterminate, use setIndeterminate(), setting it to true.

In your Java code, you can either positively set the amount of progress that has been made (via setProgress()) or increment the progress from its current amount (via incrementProgressBy()). You can find out how much progress has been made via getProgress().

Since the ProgressBar is tied closely to the use of threads — a background thread doing work, updating the UI thread with new progress information — we will hold off demonstrating the use of ProgressBar until Chapter 15.

Оглавление книги


Генерация: 1.523. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз