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: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

how To change the backgroundImage for HorizontalFieldManger while Focusing/UnFocusing

Hi,

 

I want to know how to change the backgroundImage for HorizontalFieldManger while Focusing/UnFocusing.

 

Thanks

Rakesh Shankar


import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class TestManager extends HorizontalFieldManager {
	private int arrowWidth=15;
	private int arrowHeight=60;
	Bitmap bgImg ;
	Bitmap bgFocusImg ;
	Bitmap defaultbg ;
	public TestManager(){
		super(HorizontalFieldManager.FOCUSABLE);
		//bgImg = ImageUtils.resizeBitmap(Bitmap.getBitmapResource("Enquiry_bg_one.png") , Display.getWidth()-(arrowWidth*2), this.getContentHeight());
		//bgFocusImg = ImageUtils.resizeBitmap(Bitmap.getBitmapResource("Enquiry_bg_two.png") , Display.getWidth()-(arrowWidth*2), this.getContentHeight());
		defaultbg = Bitmap.getBitmapResource("Enquiry_bg_one.png");
		bgImg  =  Bitmap.getBitmapResource("Enquiry_bg_one.png");;
		bgFocusImg = Bitmap.getBitmapResource("Enquiry_bg_two.png");;
		this.setBackground(BackgroundFactory.createBitmapBackground(defaultbg));
	}
	protected void onFocus(int direction) {
		// TODO Auto-generated method stub
		
		super.onFocus(direction);
		defaultbg  = bgFocusImg;
		invalidate();
		
	}
	protected void onUnfocus() {
		// TODO Auto-generated method stub		
		super.onUnfocus();
		defaultbg  = bgImg;
		 invalidate();
	}
	
}

 Am i missing anything ?

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: how To change the backgroundImage for HorizontalFieldManger while Focusing/UnFocusing

Hi @

 

invalidate() doesn't recreate the object.

 

You can either set the background in the paint method or just call setBackground in onFocus/onUnFocus methods.

 

Hope that helps,

 

E.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how To change the backgroundImage for HorizontalFieldManger while Focusing/UnFocusing

As maadini has suggested one option is to setBackground in onFocus and onUnfocus.  Personally I have never done this and I'm not sure that this is the right hting to do.  Instead I use paintBackground. 

 

But I beleive the official way to do this, since OS 4.6 anyway, is to use:

 

<Manager>.setBackground(int visual, Background background)

 

I suggest you use the same backgroiund for the all the visual states except VISUAL_STATE_FOCUS.

 

Let us know how you get on wit this.