Let’s deal with the code:
ProgressIndicatorView myview = new ProgressIndicatorView(0);
ProgressIndicatorModel mymodel = new ProgressIndicatorModel(0, 100, 0);
ProgressIndicatorController mycontroller = new ProgressIndicatorController();
In a similar way as we did with the Activity indicator, we have to create the ProgressIndicatorView, ProgressIndicatorModel and ProgressIndicatorController. In the example, the mymodel object is created with 0,100 and 0 values on its constructor’s parameters. The first parameter refers to the initial value of the bar, the second parameter is the maximum value and third parameter is the minimum value.
Then we create a thread. We need a thread controlling the way the bar is updated. This example thread updates the bar every 1000ms (one second).
setTitle("This is a progress bar demo for bright hub!!");
As we also did in the previous example, we have to set the controller to the model, the model and the controller to the view and the model and view to the controller.
We add a label and create our progressbar with a default style and its text horizontally centered.
Last, we create the Thread and start it.
_ customProgressThread = new ProgressThread();
Here is the custom thread we ran before. Please notice this thread does nothing, and it is here where the work which needs to be done is done. This thread just sets the value in the model created before and goes on updating it every second.
class ProgressThread extends Thread
public void run()
for(int i = 0; i <= 100; ++i)
// Dumb thread
// Work should be here
To sum up, I recommend you test with all the style options we talked about to select the most appropriate for each task. Sometimes you don't need to display the percentage because the task is not long enough, and sometimes it is. It’s up to you to make your application transitions and operations friendlier for the user.