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: 391
Registered: ‎06-22-2010
My Device: na

Focus issue in Customized tab control

I have developed a customized tab.I am adding number of bitmap field in a forloop to an hfm and i hav a vfm also.I want that when i click on the vfm,the respective tabbed image should remain focused,but the focus is going to the last image.Here is my code 

for (int j = 0; j < tabsComponent.getCount(); j++) {
			TabComponent tabComponent = (TabComponent) tabsComponent
					.getComponent(j);

			String selimg = tabComponent.getAttribute("selImg");
			if (selimg.toUpperCase().startsWith("RESOURCE://")) {
				selimg = selimg.substring(11);
			}
			final Bitmap bitmapsel = Utils.resizeImage(
					Bitmap.getBitmapResource(selimg),
					tabWidth / tabsComponent.getCount(), tabHeight);
			String Unselimg = tabComponent.getAttribute("unselImg");
			if (Unselimg.toUpperCase().startsWith("RESOURCE://")) {
				Unselimg = Unselimg.substring(11);
			}
			final Bitmap bitmapunsel = Utils.resizeImage(
					Bitmap.getBitmapResource(Unselimg), tabWidth
							/ tabsComponent.getCount(), tabHeight);
			bmField1 = new BitmapField(bitmapunsel,
					BitmapField.FOCUSABLE) {
				public void onFocus(int direction) {
					super.onFocus(direction);
					setBitmap(bitmapsel);
					if(state){
					selectedTab = 0;
					createChildView();
					}
				}
				public void onUnfocus() {
					super.onUnfocus();
					setBitmap(bitmapunsel);
				}
				 protected boolean touchEvent(TouchEvent message) {
					  super.touchEvent(message);
					   if (TouchEvent.CLICK == message.getEvent()) {
						   state=false;
							selectedTab = tabWidget.getFieldWithFocusIndex();
							createChildView();
							return true;
					   }
					return false;
				}
				protected void drawFocus(Graphics graphics, boolean on) {

				}
			};
			tabWidget.add(bmField1);
		}

 And this is my vfm

 

tabContent = new VerticalFieldManager(FOCUSABLE) {
			protected void sublayout(int maxWidth, int maxHeight) {
				super.sublayout(maxWidth, maxHeight);
				setExtent(contentWidth, contentHeight);
			}
protected void paint(Graphics g) {
	if(isFocus()){
		bmField1.getLeafFieldWithFocus().setFocus();
		
	}
	super.paint(g);
};

 I want the focus to remain on th tab image which actually have it

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

Re: Focus issue in Customized tab control

Can anybody help

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

Re: Focus issue in Customized tab control

You can't have two things focused at once.  So you need to have an indication that one field is 'selected'.  So your tab heading has to have a state where it painted appropriately.

 

The other thing with HFM is that when focus is returned to them, via the trackpad, the focus will start at the beginning if you are scrolling 'down' and at the end if you are scrolling up.  To get over this problem I suggest you try overriding onFocus, and set the Focus to the selected Bitmap.  Again you will need this ;'selected' state to enable the HFM to know which one to put focus on to.

 

Let us know if this doesn't get you going.

 

Next time, if you paste in a code sample, can you make it a simple one that demonstrates the problem and does not rely on assets or classes and methods that we can't see.  This does two things.  Firstly it means we can be confident we are seeing everything that is involved.  And secondly, we can test it!

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

Re: Focus issue in Customized tab control

How can i get an instance of each BitmapField.Actually i have not using Multiple BitmapFields,but instead put the BitmapField inside a forloop,so i want to perform specific task depending on which bitmapfield is being focused

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

Re: Focus issue in Customized tab control

Can you explain the circumstances in which you are trying to get the the Bitmap?  In other words, explain in words your 'design' and then perhaps we can suggest ways you can implement this.

 

You will clearly have to have something that distinguishes each BitmapField to ensure you know which is which, there are a wide variety of ways of doing this, one useful option is to use the Field's 'cookie' - set setCookie(..) method. 

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

Re: Focus issue in Customized tab control

Actually i have a HFM.To it i am adding BitmapFields inside a for loop.So if the loop executes for  times,five instances of BitmapFields are being added to the hfm.And than i am adding the hfm to the vfm

for (int j = 0; j <5; j++) {
			
			BitmapField bmField1 = new BitmapField(bitmapunsel,
					BitmapField.FOCUSABLE) {
				public void onFocus(int direction) {
					super.onFocus(direction);
					setBitmap(bitmapsel);
					
				}
				public void onUnfocus() {
					super.onUnfocus();
				   setBitmap(bitmapunsel);
				   
				}
				
				 protected boolean touchEvent(TouchEvent message) {
					  super.touchEvent(message);
					   if (TouchEvent.CLICK == message.getEvent()) {
						   state=false;
							selectedTab = tabWidget.getFieldWithFocusIndex();
							createChildView();
							
							return true;
					   }
					return false;
				}
				
			};
			
			hfm.add(bmField1);
		}
vfm.add(hfm);
add(vfm)

 

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

Re: Focus issue in Customized tab control

So exactly what specific processing do you need to do and how do you propose doing it?

 

I appreciate that you add the BitmapFields in a for loop, the question is at some stage, you are going to have to identify which BitmapField is which and associate some specific actions to that BitmapField.  At present you are adding 5 identical BitmapFields.  So what distinguishes each?  Is there a different image?  Is the 'index' important, so the 1st one does something and the 2nd one does something else.  Displaying 5 identical BitmapFields to the user is a little unusal, normally people expect to display different things. 

 

This is what I meant by your 'design'.  In order for this processing to work, you can't have 5 identical BitmapField can you?

 

And I appreciate at this stage you are just asking about focus.  I suspect that there are more things that you will want to do on events other than focus.  For example, you might think that you can use focus to say decide what else is on the screen.  But if you do this, the trackpad usage will in fact cause every Field to be focused as the user scrolls to the last one, which I suspect was not the user's intention.  Typically they want to scroll to something and then click to activate it. 

 

This is why I wanted you to explain in words what you were trying to do rather than just giving us your code.

 

But anyway, I have a possible solution that is specific to this problem if all you are concerned about is focus. 

 

Create a focusListener - just one.  Add the focus listener to the Fields in the for loop,  Then in the focus listener, determine which BitmapField actually has focus by only responding to the focus gained events and finding out that Field's index in the manager - so the first one will have index 0.  Then you can do specific processing for that Field.  OK?

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

Re: Focus issue in Customized tab control

Ok let me explain the entire scenario.Actually i am implementing a CustomTabBar.So bitmapfield gets added in an hfm inside forloop coz the data is coming from server.i have a vfm too which displays the contents of the selected tab.So when i click a tab,i change the vfm contents.Now when my focus is in the vfm section my selectedTab looses its focus,which i want it to hold as it will indicate that which tab is focused.

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

Re: Focus issue in Customized tab control

My first post in reply to your question on this Thread is intended to answer that question.  Please review it again.  What don't you understand in that post?

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

Re: Focus issue in Customized tab control

if i cant have two things focused at the same time,than the only option remaining is that i have to use setBitmap on bitmapfield?