![]() |
focus on verticalfieldmanager Hi 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 |
call getFieldWithFocus() |
and what type return me the function getFieldWithFocus()? in what type of variable can i save the returned value of this function? Thanks, Oscar |
It returns a Field. Take a look at the API docs for more details |
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. |
Ok, I have add this code: Field tmp; String aviso; tmp = this.getFieldWithFocus(); aviso = tmp.getAccessibleDescription(); Dialog.inform(aviso); 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 |
you have to cast the field to the subtype first: Code: if (field instanceof EditField){system.out.println((EditField)field).getText()} |
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(); } Dialog.inform(aviso); |
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); filas_aviso[cont_fila_aviso].setFocusListener(listener); c1.add(filas_aviso[cont_fila_aviso]); cont_fila_aviso++; 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 |
The code is only correct if field is an EditField, but the code doesn't check that it is. Code: if(field instanceof EditField) |
| All times are GMT -5. The time now is 06:40 AM. |
Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.