BlackBerry Forums Support Community

BlackBerry Forums Support Community (
-   Developer Forum (
-   -   focus on verticalfieldmanager (

racsus 04-22-2008 11:06 AM

focus on verticalfieldmanager

I have a hfm.add(new LabelField("fld 1", LabelField.FOCUSABLE)); in a verticalfieldmanager, how can I know the content of the actually screen focus that user has selected?

Thanks, Oscar

bdowling 04-22-2008 01:35 PM

call getFieldWithFocus()

racsus 04-22-2008 03:43 PM

and what type return me the function getFieldWithFocus()? in what type of variable can i save the returned value of this function?

Thanks, Oscar

bdowling 04-23-2008 02:24 AM

It returns a Field. Take a look at the API docs for more details

simon.hain 04-23-2008 03:10 AM

imo the most simple way to handle focus events is implementing focuschangelistener and adding it to all fields in question.
getFieldWithFocus() is used to check the focussed field if you use other methods to do something, for example in navigationclick or makemenu.

racsus 04-23-2008 03:43 AM

Ok, I have add this code:

Field tmp;
String aviso;
tmp = this.getFieldWithFocus();
aviso = tmp.getAccessibleDescription();

But the code aviso = tmp.getAccessibleDescription(); is incorrect for obtain the text of the focus field, I have studied the javadoc of Field but I don't find anything, What is the correct property for obtain the field's text?

Thanks, Oscar

simon.hain 04-23-2008 03:50 AM

you have to cast the field to the subtype first:

if (field instanceof EditField){system.out.println((EditField)field).getText()}

racsus 04-23-2008 04:35 AM

I have prove your code but never entry in the if... why? this is my code:

Field tmp;
EditField tmp2;
String aviso = "";
tmp = this.getFieldWithFocus();
if (tmp instanceof EditField){
tmp2 = (EditField)tmp;
aviso = tmp2.getText();

racsus 04-23-2008 08:50 AM

Hi again, I think that error it's when I create the fields of VerticalFieldManager:

filas_aviso[cont_fila_aviso] = new LabelField(contenido, LabelField.FOCUSABLE);

I think that i have to add this command:

private class FocusListener implements FocusChangeListener {
public void focusChanged(Field field, int eventType) {
EditField campo;
campo = (EditField)field;
aviso = campo.getText();
FocusListener listener = new FocusListener();

the code is correct, why give error in line campo = (EditField)field;

Thanks, Oscar

bdowling 04-23-2008 02:31 PM

The code is only correct if field is an EditField, but the code doesn't check that it is.


if(field instanceof EditField)
    String text = ((EdtiField)field).getText();
    // do something with text

All times are GMT -5. The time now is 09:13 AM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.