jbrohan wrote:
> Hello
> I've been having some difficulties with  the progress bar. I built a
> separate test harness and now I start to see things more clearly. The
> code below seems to work correctly, but updates the progress bar only
> when it finishes. I want it to update as the progress is made!
> 
> package com.example.progressbartest;
> <snip imports>
> 
> public class ProgressBarTest extends Activity {
>       static int i;
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         // Request the progress bar to be shown in the title
>         requestWindowFeature(Window.FEATURE_PROGRESS);
>         setContentView(R.layout.main);
>         setProgressBarVisibility(true);
> 
>         final ProgressBar progressHorizontal = (ProgressBar)
> findViewById(R.id.progress_horizontal);
>         while (i<1000){
>               setProgress(i++);
>               Log.e("John","in loop"+Integer.toString(i));
>               }
>     }
>    }

setProgress() does not set the progress on the screen.

setProgress() puts a message on a message queue that the UI thread uses.
When the UI thread eventually pops that message off of the message
queue, the UI thread will set the progress on the screen.

However, you are not letting the UI thread do that. Instead, you are
busy-looping 1000 times, calling setProgress() every time. The UI thread
cannot process messages on the queue until after that 1000-count loop is
done.

If you want Android to draw things, you have to let the UI thread go
(e.g., return from onCreate()).

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Need help for your Android OSS project? http://wiki.andmob.org/hado

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to