02-26-2013 05:17 AM - edited 02-26-2013 05:24 AM
Screen has two scrollable horizontal filed mangers with Manager.HORIZONTAL_SCROLL, while scrolling second manger once focus reached end of manger, automatically above manger items scrolling horizontally.
Example:
First manager has 10 items and below second manager has 10 items, first i do scroll down and focus will be on second manger first item, now i do right navigation once focus reached 10th item of second manager above manager items starts horizontal scroll.
This is happening on device and simulator also. i have tested on 5.0, 6.0 and 7.0 same issue is there.
Sample code sinppet:
HorizontalFieldManager hfmOuter = new HorizontalFieldManager(FOCUSABLE | Manager.HORIZONTAL_SCROLL);
for (int i = 0; i < 10; i++) {
hfmOuter.add(new LabelField(" TITLE "+i, FOCUSABLE));
}
add(hfmOuter);
HorizontalFieldManager hfmOuter1 = new HorizontalFieldManager(FOCUSABLE | Manager.HORIZONTAL_SCROLL);
for (int i = 0; i < 10; i++) {
hfmOuter1.add(new LabelField("NAME"+i, FOCUSABLE));
}
add(hfmOuter1);
Solved! Go to Solution.
02-26-2013 05:24 AM
02-26-2013 05:27 AM
02-26-2013 06:31 AM
If I understand this problem correctly, there are two potential issues:
a) When scrolling horizontally from the second manager you do not want focus to leave that Manager - instead you want the scrolling to stop.
Here is some code to do that:
protected boolean navigationMovement(int dx, int dy, int status, int time) {
int focusIndex = getFieldWithFocusIndex();
if ( focusIndex == 0 && dx < 0 && dy == 0 ) {
// scrolling left but at beginning
return true;
}
if ( focusIndex == this.getFieldCount() - 1 && dx > 0 && dy == 0 ) {
// scrolling right but at end
return true;
}
return super.navigationMovement(dx, dy, status, time);
}
The second potential problem is that you don't want the scroll to start at the 'end' of the first Manager, instead you want focus to return to the currently selected item from the first HFM. This is a more complicated problem - you need to retain an indication of which Field this was (let us call it the selected Field) and when focus returns to the Manager, set Focus on the selected entry.
Assuming you retain this selected indicator, then you override onFocus to set the focus back to the selected item, code would look something like this:
protected void onFocus(int direction) {
if ( direction != 0 && currentlySelectedField != null ) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
try {
currentlySelectedField ();
} catch (Throwable t) {
LibraryRepository.logEventError("GalleryVoucher Focus problem: " + t.toString());
}
}
});
} else {
super.onFocus(direction);
}
}
02-26-2013 06:51 AM