Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Contributor
vladluz
Posts: 4
Registered: 11-30-2010
My Carrier: Vodafone
Accepted Solution

Manager custom scroll

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? 

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: Manager custom scroll

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).

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
New Contributor
vladluz
Posts: 4
Registered: 11-30-2010
My Carrier: Vodafone

Re: Manager custom scroll

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.

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: Manager custom scroll

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.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
New Contributor
vladluz
Posts: 4
Registered: 11-30-2010
My Carrier: Vodafone

Re: Manager custom scroll

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

Please use plain text.
New Contributor
vladluz
Posts: 4
Registered: 11-30-2010
My Carrier: Vodafone

Re: Manager custom scroll

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?

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: Manager custom scroll

[ Edited ]

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.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
ankityadav4u
Posts: 231
Registered: 03-16-2011
My Carrier: AIRTEL, BSNL

Re: Manager custom scroll

if i want to move focus with scroll then what should i do in above code???


available on: Monday to Friday, Indian standard (day) time : )
  • Give kudos by clicking on the star icon to say "Thanks!" if you feel this response is helpful.
  • Click "Accept as Solution" if this post was what you needed. so that people who are trying to help will not waste their time reading a thread where no help is needed.

Please use plain text.
Developer
johnmiya
Posts: 49
Registered: 06-07-2010
My Carrier: sw

Re: Manager custom scroll

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 :smileyhappy:

Please use plain text.