Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Focus issue in custom PasswordField

I have custom PasswordEditField, which has shows border on focus. 

protected void onFocus(int direction) {
		setRoundBorder(UibaseClass.getHighlightBorderColor());
		_focus = true;
		super.onFocus(direction);
	}

protected void onUnfocus()
{
setRoundBorder(UibaseClass.getTextboxColor());
_focus = false;
super.onUnfocus();
}

Then had a problem that if user presses enter key, focus wasn't moving to next field on a PopupScreen. So I overridden keyUp method to move the focus to next field as follows:

protected boolean keyUp(int keycode, int time) {
		if(Keypad.key(keycode) == Keypad.KEY_ENTER && _nextFocusable!=null){
			_nextFocusable.setFocus();
			onUnfocus();
		}
		return super.keyUp(keycode, time);		
	}

 Now I have another problem: 

8520Dialog.png

 

If user presses Enter in 2nd passwordField, it shows 1st and 3rd focused, while I want only the 3rd field to be focused.

 

I tried to debug the code, and found out that first onUnfocus is called then onFocus is called twice.

 

Is there any way to avoid this strange behavoir? 

 

 

BlackBerry Development Advisor
Posts: 15,753
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Focus issue in custom PasswordField

onUnfocus should not be called directly (other than super.onUnFocus).  The system will make that call when a field loses focus.  Remove that call from your keyUp method.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: Focus issue in custom PasswordField

If I remove the UnFoucs() call it does not remove foucs from 2nd field. and now the 2nd and third fields are focused.

BlackBerry Development Advisor
Posts: 15,753
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Focus issue in custom PasswordField

In that situation what is _nextFocusable set to?  Is it your top most field?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: Focus issue in custom PasswordField

I want to move the focus from 1 to 2, from 2 to 3 and from 3 to a button which is below the last password field. So set the values of _nextFocusable accordingly, ex. in first field it will be second passField, in 3rd passfield it will be buttonfield.

I observed that even without this code it works great on screen but on popupScreen it doesn't move the focus. 

BlackBerry Development Advisor
Posts: 15,753
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Focus issue in custom PasswordField

Try this code and let me know the results.

 

protected boolean keyUp(int keycode, int time) {
		if(Keypad.key(keycode) == Keypad.KEY_ENTER && _nextFocusable!=null){
			_nextFocusable.setFocus();
                        return true;
		}
                else
                {
		     return super.keyUp(keycode, time);	
                }
	}

 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: Focus issue in custom PasswordField

Result is same, if I press enter key on 1st field it calls onFocus() of 2nd field and no call to onUnfocus() of 1st field. So eventually both the fields looks has got focused border.