It is not a good idea to put the Thread.sleep loop in the onCreate
method.

I recommend you use an AsyncTask to do what you are trying.

Something like this:
          public class asyncphoto extends AsyncTask<Void, String,
Void> {

                  protected Void doInBackground(Void... unused) {
                          for (String photo : photo_list) {

                           publishProgress(photo);
                           SystemClock.sleep(3000);
                          }
                          return(null);
                          }
                  @Override
                 protected void onProgressUpdate(String... photo) {

                          bm = BitmapFactory.decodeFile(photo[0]);
                  ImageView01.setImageBitmap(bm);
                  ImageView01.setScaleType
(ImageView.ScaleType.FIT_XY);

                  }
                     protected void onPostExecute(Long result) {
                         Toast
                         .makeText(AMLTimerTask.this, "Done!", 
Toast.LENGTH_SHORT)
                         .show();
                     }

          }

Just fire up the async task within your onCreate method:  new
asyncphoto().execute();

Balwinder Kaur
Open Source Development Center
·T· · ·Mobile· stick together

The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.


On Sep 4, 2:27 am, tstanly <[email protected]> wrote:
> hi all,
>
> I want to play photos like slide show,
> and I use setImageBitmap,timer and timer task to do,
> but when I enter into my app,
> it always show the final photo, not begin from fist to
> sceond,third....until final photo.
>
> I need some help, thanks
>
> ================code===============================
> package demo.app;
>
> public class photo_show_play extends Activity
> {
>
>     private List<String> photo_list;
>     private File f;
>     private File[] files;
>     private ImageView ImageView01;
>     private Gallery g;
>     private Bitmap bm;
>     private String path;
>     private int photo_num=0;
>     private int play_no;
>     private Timer timer=new Timer();
>
>     /** Called when the activity is first created. */
>           @Override
>           public void onCreate(Bundle savedInstanceState)
>           {
>             super.onCreate(savedInstanceState);
>             setContentView(R.layout.photo_show_play);
>
>             ImageView01 =(ImageView)findViewById(R.id.ImageView01);
>
>             store_photo_list();
>             play_no=0;  //index=0
>
>             timer.schedule(new photo_task(), 1000, 3000);
>
>             try {
>                         Thread.sleep(photo_num*3000);
>                 } catch (InterruptedException e) {
>                         // TODO Auto-generated catch block
>                         e.printStackTrace();
>                 }
>
>                 timer.cancel();
>
>           } /* end of onCreate */
>
>           private void store_photo_list()
>           {
>
>            photo_list=new ArrayList<String>();
>             f=new File(path);
>             files=f.listFiles();
>
>             for(int i=0;i<files.length;i++)
>             {
>               File file=files[i];
>               if(getImageFile(file.getPath())){
>                 photo_list.add(file.getPath());
>                 photo_num=photo_num+1;
>               }
>             } /* end of for */
>           } /* end of store_photo_list */
>
>           private boolean getImageFile(String fName)
>           {
>             boolean re;
>
>             String end=fName.substring(fName.lastIndexOf(".")+1,
>                           fName.length()).toLowerCase();
>
>             if(end.equals("jpg")||end.equals("gif")||end.equals("png")
>                     ||end.equals("jpeg")||end.equals("bmp"))
>             {
>               re=true;
>             }
>             else
>             {
>               re=false;
>             }
>             return re;
>           } /* end of getImageFile class */
>
>           public class photo_task extends TimerTask{
>                 @Override
>                 public void run() {
>                         // TODO Auto-generated method stub
>                         //play_photo(play_no);
>
>                         bm = 
> BitmapFactory.decodeFile(photo_list.get(play_no).toString());
>                         ImageView01.setImageBitmap(bm);
>                         ImageView01.setScaleType(ImageView.ScaleType.FIT_XY);
>
>                         play_no=play_no+1;
>
>                 } /* end of run */
>           } /* end of photo_task class */
>
> } /* end of photo_show_play class */
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to