Re: [android-developers] Re: While Loop Stall the rest of the program
Hello ArcDroid, From my experience, the design concept should be as follow: We will have 2 threads: Main Thread will provide a call back for Image Thread to set image to ImageView. Image Thread will download/ load the bitmap, then use the call back to set Bitmap to ImageView. The call back can be either a method/ function in Main Thread that's wrapped by runOnUiThread or implemented by Handler of Main Thread. You can also try to update the ImageView in runOnUiThread, but that's not a good design, however, it will work. BR, Nam On Sun, 2010-09-26 at 01:29 -0700, ArcDroid wrote: I originally tried a separate thread, but couldn't update the ImageView from my new thread. On Sep 26, 1:23 am, ArcDroid jacobrjohn...@gmail.com wrote: the first picture never loads with the while loop. Once the loop is removed the first picture loads just fine. right now it doesn't load the first pic, but will show the second after 5 seconds. Thanks //start with picture 1 main.setImageResource(R.drawable.pic1); //after 5 seconds load another picture int pause = 5; while ( System.currentTimeMillis() = startTime + (pause * 1001)){ if (System.currentTimeMillis() = startTime + (pause * 1001)) { main.setImageResource(R.drawable.pic2); }} On Sep 26, 1:18 am, Kumar Bibek coomar@gmail.com wrote: Ummm, you should mention more details, as to what and how you are doing things. Else, no one can answer your query. -Kumar Bibekhttp://techdroid.kbeanie.com On Sep 26, 12:45 pm, ArcDroid jacobrjohn...@gmail.com wrote: Hello, I am trying to load a picture, then run a while loop. The problem is that the program runs the while loop and doesn't load the pictures until the loop has finished. Any help is appreciated. Thanks Jake -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: While Loop Stall the rest of the program
Hello ArcDroid, From my experience, the design concept should be as follow: We will have 2 threads: Main Thread will provide a call back for Image Thread to set image to ImageView. Image Thread will download/ load the bitmap, then use the call back to set Bitmap to ImageView. The call back can be either a method/ function in Main Thread that's wrapped by runOnUiThread or implemented by Handler of Main Thread. You can also try to update the ImageView in runOnUiThread, but that's not a good design, however, it will work. BR, Nam On Sep 26, 2:45 pm, ArcDroid jacobrjohn...@gmail.com wrote: Hello, I am trying to load a picture, then run a while loop. The problem is that the program runs the while loop and doesn't load the pictures until the loop has finished. Any help is appreciated. Thanks Jake -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: While Loop Stall the rest of the program
Ummm, you should mention more details, as to what and how you are doing things. Else, no one can answer your query. -Kumar Bibek http://techdroid.kbeanie.com On Sep 26, 12:45 pm, ArcDroid jacobrjohn...@gmail.com wrote: Hello, I am trying to load a picture, then run a while loop. The problem is that the program runs the while loop and doesn't load the pictures until the loop has finished. Any help is appreciated. Thanks Jake -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: While Loop Stall the rest of the program
the first picture never loads with the while loop. Once the loop is removed the first picture loads just fine. right now it doesn't load the first pic, but will show the second after 5 seconds. Thanks //start with picture 1 main.setImageResource(R.drawable.pic1); //after 5 seconds load another picture int pause = 5; while ( System.currentTimeMillis() = startTime + (pause * 1001)){ if (System.currentTimeMillis() = startTime + (pause * 1001)) { main.setImageResource(R.drawable.pic2); }} On Sep 26, 1:18 am, Kumar Bibek coomar@gmail.com wrote: Ummm, you should mention more details, as to what and how you are doing things. Else, no one can answer your query. -Kumar Bibekhttp://techdroid.kbeanie.com On Sep 26, 12:45 pm, ArcDroid jacobrjohn...@gmail.com wrote: Hello, I am trying to load a picture, then run a while loop. The problem is that the program runs the while loop and doesn't load the pictures until the loop has finished. Any help is appreciated. Thanks Jake -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: While Loop Stall the rest of the program
I originally tried a separate thread, but couldn't update the ImageView from my new thread. On Sep 26, 1:23 am, ArcDroid jacobrjohn...@gmail.com wrote: the first picture never loads with the while loop. Once the loop is removed the first picture loads just fine. right now it doesn't load the first pic, but will show the second after 5 seconds. Thanks //start with picture 1 main.setImageResource(R.drawable.pic1); //after 5 seconds load another picture int pause = 5; while ( System.currentTimeMillis() = startTime + (pause * 1001)){ if (System.currentTimeMillis() = startTime + (pause * 1001)) { main.setImageResource(R.drawable.pic2); }} On Sep 26, 1:18 am, Kumar Bibek coomar@gmail.com wrote: Ummm, you should mention more details, as to what and how you are doing things. Else, no one can answer your query. -Kumar Bibekhttp://techdroid.kbeanie.com On Sep 26, 12:45 pm, ArcDroid jacobrjohn...@gmail.com wrote: Hello, I am trying to load a picture, then run a while loop. The problem is that the program runs the while loop and doesn't load the pictures until the loop has finished. Any help is appreciated. Thanks Jake -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: While Loop Stall the rest of the program
The View gets updated only after your method is done executing. So, when you call setImageResource() the view is not immediately updated. You should use a separate thread for your for loop, and I can think of 2 options right now: 1. Use a Thread and a Handler to update the UI ( http://developer.android.com/guide/appendix/faq/commontasks.html#threading) 2. Use an AsyncTask ( http://developer.android.com/reference/android/os/AsyncTask.html) Hope it helps, YuviDroid On Sun, Sep 26, 2010 at 10:29 AM, ArcDroid jacobrjohn...@gmail.com wrote: I originally tried a separate thread, but couldn't update the ImageView from my new thread. On Sep 26, 1:23 am, ArcDroid jacobrjohn...@gmail.com wrote: the first picture never loads with the while loop. Once the loop is removed the first picture loads just fine. right now it doesn't load the first pic, but will show the second after 5 seconds. Thanks //start with picture 1 main.setImageResource(R.drawable.pic1); //after 5 seconds load another picture int pause = 5; while ( System.currentTimeMillis() = startTime + (pause * 1001)){ if (System.currentTimeMillis() = startTime + (pause * 1001)) { main.setImageResource(R.drawable.pic2); }} On Sep 26, 1:18 am, Kumar Bibek coomar@gmail.com wrote: Ummm, you should mention more details, as to what and how you are doing things. Else, no one can answer your query. -Kumar Bibekhttp://techdroid.kbeanie.com On Sep 26, 12:45 pm, ArcDroid jacobrjohn...@gmail.com wrote: Hello, I am trying to load a picture, then run a while loop. The problem is that the program runs the while loop and doesn't load the pictures until the loop has finished. Any help is appreciated. Thanks Jake -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- YuviDroid Check out Launch-X http://android.yuvalsharon.net/launchx.php (a widget to quickly access your favorite apps and contacts!) http://android.yuvalsharon.net -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en