BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-22-2008, 12:06 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default focus on verticalfieldmanager

Please Login to Remove!

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
Offline  
Old 04-22-2008, 02:35 PM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

call getFieldWithFocus()
Offline  
Old 04-22-2008, 04:43 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Thanks, Oscar
Offline  
Old 04-23-2008, 03:24 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

It returns a Field. Take a look at the API docs for more details
Offline  
Old 04-23-2008, 04:10 AM   #5 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 04-23-2008, 04:43 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Offline  
Old 04-23-2008, 04:50 AM   #7 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

you have to cast the field to the subtype first:
Code:
if (field instanceof EditField){system.out.println((EditField)field).getText()}
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 04-23-2008, 05:35 AM   #8 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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);
Offline  
Old 04-23-2008, 09:50 AM   #9 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Last edited by racsus : 04-23-2008 at 12:08 PM.
Offline  
Old 04-23-2008, 03:31 PM   #10 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Code:
if(field instanceof EditField)
{
    String text = ((EdtiField)field).getText(); 
    // do something with text
}
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.