Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
arunbiet
Posts: 384
Registered: ‎06-22-2010
My Device: na

Re: Auto Refresh a Screen

Below is my complete code

 

import java.util.Timer;
import java.util.TimerTask;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;


public final class MyScreen extends MainScreen
{
   BitmapField bmp;
   Bitmap image;
   int i=1;
   String img []= {"1.jpg","2.jpg","3.jpg","4.jpg","5.jpg"};
    public MyScreen()
    {      
    	
    	ScheduleLoader loader = new ScheduleLoader();
		Timer timer = new Timer();
		timer.schedule(loader, 1 * 3000);
		bmp=new BitmapField(Bitmap.getBitmapResource(img[i]));
		add(bmp);
    }
    class ScheduleLoader extends TimerTask {
    	public void run() {
    		UiApplication.getUiApplication().invokeLater(new Runnable() {
    			public void run() {
    				
    				bmp.setBitmap(Bitmap.getBitmapResource(img[i]));
    				i++;
    			}
    		});
    	}
    }
 }

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Auto Refresh a Screen

you schedule your task to run once only, if you check my last post i gave you the link to another method (schedule with tt and two longs) which is used for repeated execution.

put i++ up front, otherwise the first run will show you the same picture you already have.
you should also reset i if you want to show the pictures as an animation, or cancel the tt, otherwise you will run into an array out of bounds.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
pradeep_ch
Posts: 543
Registered: ‎12-23-2010
My Device: Z10

Re: Auto Refresh a Screen

I think this is the best example for your issue.

 

http://supportforums.blackberry.com/t5/Java-Development/Display-an-animated-GIF/ta-p/445014

 

Thanks

Developer
arunbiet
Posts: 384
Registered: ‎06-22-2010
My Device: na

Re: Auto Refresh a Screen

Thanx Simon it worked for me.And thanx to pradeep too,though it was nt what i was looking for,but thanx fr taking the effort to post a solution :Clap: