BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 04-20-2010, 04:35 AM   #1
niceonedave
Knows Where the Search Button Is
 
Join Date: Aug 2009
Model: 8800
PIN: N/A
Carrier: O2
Posts: 30
Default How to properly handle focus traversal in custom field

Please Login to Remove!

I have implemented a custom field by extending the Manager class. The field is quite simple, it consists of a label and two check boxes, yes and no. The fields are laid out so that the label is on the left and uses as much space as it can while still allowing room for the check boxes which are positioned next to each other at the right and vertically centred compared to the label (if it spans more than one line). So it looks like this:

This is a question? O Yes O No

Everything is fine so far in terms of laying out the fields. But now I am trying to handle focus traversal. First of all the default behaviour when the user scrolls up or down is to move between the yes and no options. I want to move to the next field above or below when up or down is pressed, so I did this:

Code:
protected int moveFocus(int amount, int status, int time) {
	if (status == 537001984 || status == -1610481664) { // Up or down was pressed
		// Don't move focus between yes and no when up or down is pressed.
		return amount;
	}
	return super.moveFocus(amount, status, time);
}
And that seems to work.

The next thing I would like to do is to remember which option last had the focus when the field loses focus, then on gaining focus again (regardless of which direction the focus comes from) set this field to have the focus. I tried overriding onUnfocus and onFocus so that onUnfocus I note which field was focussed then onFocus setFocus to that field. But I get a StackOverflowError, I guess because the call to setFocus on a field within the manager actually calls onFocus for the manager itself again??

So does anyone know how I should be doing this? I checked the DateField and it has the exact behaviour I am looking for, i.e. it remembers if you were last on the day, month or year field and sets this field to focus when the field itself gets the focus.
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Serta Big and Tall Commercial Office Chair Memory Foam 350 Lb Capacity Black NEW picture

Serta Big and Tall Commercial Office Chair Memory Foam 350 Lb Capacity Black NEW

$169.99



PIC18F87K22 EasyPIC PRO™ v7 PIC® PIC MCU 8-Bit Embedded Evaluation Board picture

PIC18F87K22 EasyPIC PRO™ v7 PIC® PIC MCU 8-Bit Embedded Evaluation Board

$109.99



New In Box SIEMENS 6ES7954-8LF03-0AA0 6ES7 954-8LF03-0AA0 Memory Card picture

New In Box SIEMENS 6ES7954-8LF03-0AA0 6ES7 954-8LF03-0AA0 Memory Card

$246.08



Nightingale CXO 6200 Memory Foam, New Headrest, Lumbar Support Ergo Office Chair picture

Nightingale CXO 6200 Memory Foam, New Headrest, Lumbar Support Ergo Office Chair

$415.00



SeeSii NanoVNA-H4 Vector Network Analyzer 4

SeeSii NanoVNA-H4 Vector Network Analyzer 4" Handheld TFT MF Antenna Analyzer

$59.99



New Sealed AB 2080-MEMBAK-RTC Memory Backup, Data Log, Recipe ,High Accuracy RTC picture

New Sealed AB 2080-MEMBAK-RTC Memory Backup, Data Log, Recipe ,High Accuracy RTC

$286.59







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