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
Posts: 406
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer
Accepted Solution

Auto Refresh a Screen

How can i refresh my screen  & fields in every 5 seconds

Developer
Posts: 16,612
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Auto Refresh a Screen

if you use setText or something similar the screen is automatically updated.
you can use invalidate to refresh it, but that would only be useful if you use custom painting.
----------------------------------------------------------
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
Posts: 406
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Auto Refresh a Screen

Invalidate() not at all working

Developer
Posts: 16,612
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Auto Refresh a Screen

what do you want to refresh in the first place?
as i already said, for textfields a call to setText is sufficient to refresh it.
----------------------------------------------------------
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
Posts: 406
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Auto Refresh a Screen

I want to keep cganging  a BitmapField

Developer
Posts: 16,612
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Auto Refresh a Screen

call setBitmap on it, this automatically refreshes it to the new picture.

you can use a timertask if you want to do it periodically.
----------------------------------------------------------
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
Posts: 406
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Auto Refresh a Screen

Ok thank you for your guidance.Can you provide any sample code if possible?

Developer
Posts: 406
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Auto Refresh a Screen

This is my block of code.It only loads the firts image and than nothing happnens 

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=0;
   String img []= {"1.jpg","2.jpg","3.jpg","4.jpg","5.jpg"};
    public MyScreen()
    {      
    	deleteAll();
    	ScheduleLoader loader = new ScheduleLoader();
		Timer timer = new Timer();
		timer.schedule(loader, 1 * 3000);
		bmp=new BitmapField();
		add(bmp);
    }
    class ScheduleLoader extends TimerTask {
    	public void run() {
    		UiApplication.getUiApplication().invokeLater(new Runnable() {
    			public void run() {
    				invalidate();
    				bmp.setBitmap(Bitmap.getBitmapResource(img[i]));
    				i++;
    			}
    		});
    	}
    }
 }

 Kindly help me to get this done.

Developer
Posts: 16,612
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Auto Refresh a Screen

remove deleteAll(), it does not do anything.
you set i to 0, but do you have a '0.jpg'? your string array does not contain it at least. maybe you should initialize your bitmapfield with a bitmap as well.

you want repeated execution, use http://www.blackberry.com/developers/docs/7.1.0api/java/util/Timer.html#schedule(java.util.TimerTask...

remove the invalidate from the timertask, as stated above it does not do anything useful.
----------------------------------------------------------
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
Posts: 406
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Auto Refresh a Screen

I removed deleteAll() and invalidate and also initializing the bitmapfield witha bitmap like this 

bmp=new BitmapField(Bitmap.getBitmapResource(img[i]));

 bt still it bears no fruit,only the first image is being loaded and after that nothing is happening