02-06-2011 01:28 AM
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
02-07-2011 09:17 AM
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.
02-07-2011 09:42 AM
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
...
}