11-30-2010 01:17 PM
Hi!
I have a VerticalFieldManager with my oen custom fields, non of them are focusable, and what i want is, when I scroll the manager I don't want the manager to jump to the next field, instead i just want the manager to scroll down.
is there any way to accomplish this?
Solved! Go to Solution.
11-30-2010 02:10 PM
Welcome to the forums!
If you have no focusable fields whatsoever (your manager is for display only, not for the user interaction), you can override navigationMovement() and use setVerticalScroll() to scroll according to your needs.
Something like that should work:
private static final int SCROLL_STEP = 30;
...
VerticalFieldManager vfm = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR) {
private int totalHeight = 0;
private int screenHeight = 0;
private int scrollPosition = 0;
protected void sublayout(int w, int h) {
super.sublayout(w, h);
totalHeight = getVirtualHeight();
screenHeight = getVisibleHeight();
scrollPosition = getVerticalScroll();
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
if (dy != 0) {
scrollPosition += SCROLL_STEP * dy;
scrollPosition Math.min(totalHeight - screenHeight, scrollPosition);
scrollPosition = Math.max(0, scrollPosition);
setVerticalScroll(scrollPosition);
return true;
}
return super.navigationMovement(dx, dy, status, time);
};
If you have focusable fields and want some more sophisticated behavior, like slowly going through the non-focusable parts and changing focus to focusable fields when they become visible, the task becomes much more complex (a project on its own for several weeks/months).
12-02-2010 09:06 AM
Thanks a lot arkadyz ,
It really works, the only problem is that the manager keep scrolling down even if there is nothing else to show, But I think I can manage that.
12-02-2010 09:29 AM
Because it is bigger than you expect it to be. This can happen if you specify USE_ALL_HEIGHT in a Manager added to a MainScreen created with either default constructor or explicit VERTICAL_SCROLL, for example.
Can you add a debug print and find out what are the values returned by getVisibleHeight and getVirtualHeight? If your virtual height is close to 1073741823 (Integer.MAX_VALUE >> 1), you have a vertically scrolling Manager enveloping this one.
12-02-2010 10:30 AM
My screen style is NO_VERTICAL_SCROLL | USE_ALL_WIDTH and unless I miss something none of my fields have USE_ALL_HEIGHT.
My Total height is 1318 Screen height is 0 and my fields end at ~1020
12-02-2010 10:36 AM
I got it the problem was that getVisibleHeight() returns 0, changed it to getHeight() and it return the screen height correctly. Now the scroll spots at the end of the last field.
Just tell me one more thing with reply should I accept as the solution so that others facing the same problem can understand this issue.
The one where you posted the code or the last one?
12-02-2010 11:27 AM - last edited on 12-02-2010 11:30 AM
I'll edit my post with the code and replace getVisibleHeight() with getHeight() - I'm not sure what went wrong with it, since either should work. You can then accept that post as a solution - I hope it is enough for the future visitors who click "Go to Solution" button.
Edit: Oops, cannot edit that post anymore. Accept your last post as a solution - this Thread is not that long so future visitors should find the code easily.
04-27-2011 05:51 AM
if i want to move focus with scroll then what should i do in above code???
05-20-2011 03:21 AM
if I use this code Scrolling is done nicely But the problem is if i scrolled up then texts are disappear and comes white screen , when i changed dy value as dy >0 then texts did not disappear but the another field manager( which is in upper of the screen) labels are not focusable, how should i rectify this issue, i think its depends upon dy value.. please help me out ![]()