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
New Contributor
Posts: 8
Registered: ‎02-16-2012
My Device: 8900
My Carrier: airtel

ToolBar - with Image Problem

I want to create a toolbar like the one we see in twitter application. 

I have created one like this. Have used custom manager,  to distribute image evenly the whole length

 

Manager Class is as following

Manager customManager = new Manager(0)
{
protected void sublayout(int width, int height) {
setPositionChild(
getField(0), 
0, 
0);
layoutChild(
getField(0), 
getField(0).getPreferredWidth(), 
getField(0).getPreferredHeight());
setPositionChild(
getField(1), 
Graphics.getScreenWidth()/2 - getField(1).getPreferredWidth()/2, 
0);
layoutChild(
getField(1), 
getField(1).getPreferredWidth(), 
getField(1).getPreferredHeight());
setPositionChild(
getField(2), 
Graphics.getScreenWidth() - getField(2).getPreferredWidth(), 
0);
layoutChild(
getField(2), 
getField(2).getPreferredWidth(), 
getField(2).getPreferredHeight());
setExtent(width, 30);
} 
};

 

 

 

I add images in the manager as following

DesignToolBar(customManager);

 

	private void DesignToolBar(Manager hfm) {
         
		Bitmap imgInbox = Bitmap.getBitmapResource("inbox-32.png");
		fldInbox = new BitmapField(imgInbox){
			protected boolean navigationClick(int status, int time) {
				Dialog.alert("Inbox"); 
				// KeypadListener.STATUS_FOUR_WAY or KeypadListener.STATUS_TRACKWHEEL
				return true; //this says you handled the event
			}
		};
		//fldInbox.setChangeListener(customListener);
		
		Bitmap imgOutbox = Bitmap.getBitmapResource("outbox-32.png");
		fldOutbox = new BitmapField(imgOutbox){
			protected boolean navigationClick(int status, int time) {
				Dialog.alert("Outbox");  
				// KeypadListener.STATUS_FOUR_WAY or KeypadListener.STATUS_TRACKWHEEL
				return true; //this says you handled the event
			}
		};
		//fldOutbox.setChangeListener(customListener);
		
		Bitmap imgSearch = Bitmap.getBitmapResource("search-32.png");
		search = new BitmapField(imgSearch){
			protected boolean navigationClick(int status, int time) {
				Dialog.alert("Search"); 
				return true; //this says you handled the event
			}
		};
		//search.setChangeListener(customListener);
		
		hfm.add(fldInbox);
		hfm.add(fldOutbox);
		hfm.add(search);
		hfm
		.setBackground(BackgroundFactory.createLinearGradientBackground(Color.WHITESMOKE,Color.WHITESMOKE,Color.DARKGRAY,Color.DARKGRAY));
		
	}

 

 

The images display fine. But when I click them nothing happens. Am I missing something ?

New Contributor
Posts: 8
Registered: ‎02-16-2012
My Device: 8900
My Carrier: airtel

Re: ToolBar - with Image Problem

Changed the code to following

 

fldInbox = new BitmapField(imgInbox, Field.FOCUSABLE|Field.HIGHLIGHT_FOCUS){
			protected boolean navigationClick(int status, int time) {
				Dialog.alert("Inbox"); 
				// KeypadListener.STATUS_FOUR_WAY or KeypadListener.STATUS_TRACKWHEEL
				return true; //this says you handled the event
			}
		};

 

 

Even then, Alert is not displaying !