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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
rakesh86shankar
Posts: 915
Registered: ‎05-22-2009

How to get the name of focused field

Hello Guys,I want to know the name  of the presently focused field in the application,

 

By setting field.setFocusListener(this);

 

and checking FocusChange(),is that the only option,Focus in the application got stuck somewhere

 

 

I am using Navigation Click ,in all the managers that i use,Besides i am using the application for storm device,But When i click some field via touch ,i am not getting focus to field ,But when i scroll the mouse of the computer , i get the movementof  focus to the field,

 

 

AnyIdeas on this.

 

 

Regards

 

Rakesh Shankar.P

 

 

 

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: ‎12-27-2010

Re: How to get the name of focused field

If you're using a heavily customized field you may have to override touchEvent() as well. As far as the focus issue goes, you can also use Manager.getFieldWithFocus() to see what Field or Manager currently has focus.

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Carrier: various

Re: How to get the name of focused field

There is no such thing in Java as "the name of the Object", Field included. There are references which can easily change around - several references can point to the same object, the same reference might point at different objects at different times, etc.

 

If you want to find out what field is currently focused and branch your code based on that, you can (I'm giving just a couple ideas - hopefully they provide you with enough food for thought):

1) compare the field you extract from getLeafFieldWithFocus with the fields of concern:

 

Field currField = getLeafFieldWithFocus();
if (currField == cancelButton) {
  ...
} else if (currField == okButton) {
  ...
} else if (currField == mainList) {
  ...
}

 2) use Field.setCookie() to associate a different Object with each field, then extract that cookie and branch your decision during run time:

 

ButtonField okButton = new ButtonField("OK");
okButton.setCookie(new Integer(ACTION_OK));
ButtonField cancelButton = new ButtonField("Cancel");
cancelButton.setCookie(new Integer(ACTION_CANCEL));
...
add(okButton);
add(cancelButton);
...

// elsewhere in your code
Field currField = getLeafFieldWithFocus();
Integer cookie = (Integer) currField.getCookie();
if (cookie != null) {
  switch (cookie.intValue()) {
  case ACTION_OK:
     ...
     break;
  case ACTION_CANCEL:
     ...
     break;
  ...
  default:
    break;
} else {
  // some default processing
  ...
}

 

 

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.