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: 80
Registered: ‎03-19-2009
My Device: Not Specified
Accepted Solution

How to prevent focus leaving manager by trackball ?

I have a custom manager (Child Manager) with ListField, BasicEditField,.. This manager is a child of other manager (Parent Manager). I want to keep focus in first manager when scroll by TRACKBALL...(focus only move around child fields of First Manager, not go to others child fields of Parent Manager) and I still can set focus manually for others child fields of Parent Manager. Help me ! Thanks very much !

PPCLINK Blackberry Team
The Best Software for Smartphone World.
Website : www.ppclink.com
Developer
Posts: 80
Registered: ‎03-19-2009
My Device: Not Specified

Re: How to prevent focus leaving manager by trackball ?

Help me ! Smiley Sad Thanks very much !

PPCLINK Blackberry Team
The Best Software for Smartphone World.
Website : www.ppclink.com
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: How to prevent focus leaving manager by trackball ?

Hi,

 

Implement FocusListener Interface to handle focus event.

 

Suppose you have 3 components say Labelfield,ButtonField and TextField in your child manager when focus is on the last element of this child manager set focus to first element of child manager.

 

Write all this logic in the

 

public void focusChanged(Field field,int eventType){

 

 

I will try to post the code soon

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: How to prevent focus leaving manager by trackball ?

Hi,

 

here is the solution for your problem.Please find the code below

 

/* * FocusControlManager.java * * © <your company here>, 2003-2008 * Confidential and proprietary. */ import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.component.ButtonField; import net.rim.device.api.ui.component.RichTextField; import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.ui.container.VerticalFieldManager; import net.rim.device.api.ui.FocusChangeListener; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.Manager; /** * */ class FocusControlManager extends MainScreen implements FocusChangeListener{ VerticalFieldManager managerOne = null; VerticalFieldManager managerTwo = null; VerticalFieldManager managerBag = null; VerticalFieldManager managerTemp = null; LabelField objLabelOne = null; LabelField objLabelTwo = null; ButtonField objButtonOne = null; ButtonField objButtonTwo = null; public int counter = 0; FocusControlManager(){ drawComponent(); drawManager(); add(managerBag); } private void drawComponent(){ objLabelOne = new LabelField("ABC:",LabelField.FOCUSABLE); objLabelTwo = new LabelField("123:",LabelField.FOCUSABLE); objButtonOne = new ButtonField("Button One"); objButtonTwo = new ButtonField("Button Two"); } private void drawManager(){ managerOne = new VerticalFieldManager(); managerTwo = new VerticalFieldManager(); managerBag = new VerticalFieldManager(); managerOne.add(objLabelOne); managerOne.add(objButtonOne); managerBag.add(managerOne); managerBag.add(objLabelTwo); managerBag.add(objButtonTwo); managerBag.setFocusListener(this); } public void focusChanged(Field field,int eventType){ Manager vertManager; vertManager = (Manager)field; if(vertManager.getFieldWithFocusIndex() == 1){ vertManager.getField(0).setFocus(); } } }

Just let me know whether it solved your problem or not.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Highlighted
Developer
Posts: 80
Registered: ‎03-19-2009
My Device: Not Specified

Re: How to prevent focus leaving manager by trackball ?

Thanks Rajat_10Sep for your reply ! Your solution is work. But in case I scroll trackball very fast. Focus still leave my child manager (and your managerBag). You can try again. I have solved my problem by override MoveFocus(). This is my code :

 

 

protected int moveFocus(int amount, int status, int time) { int focusIndex = this.getFieldWithFocusIndex(); int ret; if (amount < 0 && (focusIndex + amount) < 0) { ret = super.moveFocus(0, status, time); } else if ( amount > 0 && (focusIndex + amount) >= getFieldCount()) { ret = super.moveFocus(0, status, time); (getField(0)).setFocus(); } else ret = super.moveFocus(amount, status, time); return ret; }

 

 


PPCLINK Blackberry Team
The Best Software for Smartphone World.
Website : www.ppclink.com
Contributor
Posts: 10
Registered: ‎03-10-2010
My Device: 9550
My Carrier: Vodaphone

Re: How to prevent focus leaving manager by trackball ?

I think the more simpler way is just override the nextFocus() and never returns -1 from that method.