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
-~----------~----~----~----~------~----~------~--~---