BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-02-2010, 09:32 AM   #1 (permalink)
New Member
 
SergioTapia's Avatar
 
Join Date: Aug 2010
Model: 7100T
PIN: N/A
Carrier: asdfasdf
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How to detect when a control has lost focus?

Please Login to Remove!

I have an EditField control on my application UI and when a user clicks on it, the keyboard appears. I want to hide that keyboard programatically when that particular edit field loses focus.

Any suggestions?

Also, since I'm using a simulator, how can I save information like to a text file to save information?

something like:
"Sergio Tapia|10 July 2010|21|Egypt|Male"
"Monica July|10 July 2002|42|Cairo|Female"
"Sergio Tapia|10 July 2010|21|Egypt|Male"

Symol delimited values.

Last edited by SergioTapia : 09-02-2010 at 09:34 AM.
Offline  
Old 09-02-2010, 09:39 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You can set a FocusChangeListener on the field, then hide the keyboard when the field loses focus.
Offline  
Old 09-02-2010, 09:44 AM   #3 (permalink)
New Member
 
SergioTapia's Avatar
 
Join Date: Aug 2010
Model: 7100T
PIN: N/A
Carrier: asdfasdf
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help, your suggestion makes complete sense however I do not have a FocusChangeNotify method to attach to my EditField txtAmount. Any suggestions?

Code:
final class ExpenseSheetScreen extends MainScreen implements FieldChangeListener{
    public ExpenseSheetScreen() {
        super();
        txtAmount = new EditField(Field.FIELD_RIGHT);
        txtAmount.focusChangeNotify(arg0)????  
        add(txtAmount);
    }
}
Thanks for the help.

Also what code do I need to use to actually hide the keyboard?
Offline  
Old 09-02-2010, 10:07 AM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You create a FocuChangeListener, then add this listener to your field using setFocusChangeListener()

The listener has a method that is called when the focus changes (gained/lost).

This is covered in the developers guide, and the javadocs.

For the keybard, how about

VirtualKeyboard.setVisibility()

Again, this is covered in the javadocs, the developers guide, and in the 4.7 or 5.0 sample code.
Offline  
Old 09-02-2010, 10:25 AM   #5 (permalink)
New Member
 
SergioTapia's Avatar
 
Join Date: Aug 2010
Model: 7100T
PIN: N/A
Carrier: asdfasdf
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help, now I'm having trouble understand what you're trying to say.

Code:
public void focusChanged(Field field, int eventType) {
	if ( field == txtAmount && eventType == 1)
	{
		VirtualKeyboard.HIDE();
	}			
}
I have that code above, and the change event seems that it's going to work (haven't test it yet) - what number is the eventType when a control loses focus? Also, I'm getting an error on the Hide() method.

"The method HIDE() is undefinied for the type VirtualKeyboard."

Thanks again for the help.
Offline  
Old 09-02-2010, 10:45 AM   #6 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You should spend some time reading the docs and looking at the sample code.

VirtualKeyboard.HIDE is a constant definition, it is not a method.

You get an instance of the virtual keyboard by asking the screen for it, using getVirtualKeyboard()

Then you pass the VirtualKeyboard.HIDE to setVisibility() method.
Offline  
Old 09-02-2010, 10:50 AM   #7 (permalink)
New Member
 
SergioTapia's Avatar
 
Join Date: Aug 2010
Model: 7100T
PIN: N/A
Carrier: asdfasdf
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks now I have this:

Code:
public void focusChanged(Field field, int eventType) {
	if ( field == txtAmount && eventType == 1)
	{
		getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE);
	}			
}
Now my problem is that the keyboard isn't hiding. I think the error is in the eventType parameter. What number identifies a LostFocus event? I hard coded in '1' for tests but it doesnt seem to work.

Code:
FocusChangeListener focusListener;
    
    //In the constructor:
    txtAmount = new EditField(Field.FIELD_RIGHT);
    txtAmount.setFocusListener(focusListener);

public void focusChanged(Field field, int eventType) {
	if ( field == txtAmount && eventType == 1)
	{
		getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE);
	}			
}
why isn't this working? Thanks
Offline  
Old 09-02-2010, 11:51 AM   #8 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

It's in the javadocs:

FocusChangeListener.FOCUS_GAINED
FocusChangeListener.FOCUS_LOST
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.