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
Super Contributor
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Problem while detecting the scrolling data using ScrollChangeListener.

hi there,

 

i am trying to use scroll Change listener here while i am scrolling down the manager. i did get the selected values.

 

Can anyone help me on this is this correct approach or not.

i added some fields to the manager but when i scroll down to the screen  then the Scroll change listener was not called.

 

 

public class ScrollableVerticalManager extends VerticalFieldManager implements
		ScrollChangeListener {

	private onClickListener listener;

	public ScrollableVerticalManager(String parameter, onClickListener listener) {
		this(VERTICAL_SCROLL | VERTICAL_SCROLLBAR, parameter, listener);
		// TODO Auto-generated constructor stub
	}

	public ScrollableVerticalManager(long style, String parameter,
			onClickListener listener) {
		super(style);
		setScrollListener(this);
		this.listener = listener;
	}

	public void scrollChanged(Manager manager, int newHorizontalScroll,
			int newVerticalScroll) {
		System.out.println("total Height of the manager:"
				+ manager.getVirtualHeight());
		System.out.println("Visible Height of the manager:"
				+ manager.getVisibleHeight());
		System.out.println("New Height of the Manager" + newVerticalScroll);
		/*
		 * if (manager.getVirtualHeight() > manager.getVisibleHeight()) {
		 * System.out.println(); }
		 */
	}

}

 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Problem while detecting the scrolling data using ScrollChangeListener.

It's not new height of the manager - rather new vertical scrolling position (just as its name implies), but the idea is right - you can detect the scrolling events and the corresponding positions this way.

 

The main question is: what are you trying to achieve? For example, if you want some field or background picture "docked" on the screen, you should update its position and schedule repaint for it on each scrollChanged (by invalidating the appropriate portions of the screen, for example). Or, if you need to download/read from SD card some additional data as the screen is scrolled towards the fields displaying them, you can initiate the I/O or network operation in a separate Thread according to the new scrolling position.

 

These are just a couple of examples - see how your design fits there. If you have doubts, give more details and ask again.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem while detecting the scrolling data using ScrollChangeListener.

[ Edited ]

Can you try to explain you problem another way?  Sorry, I don't understand it. 

Super Contributor
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: Problem while detecting the scrolling data using ScrollChangeListener.

Actually

 

i want to make a server call when the user scrolls down at the end of the field. how can i do that is Scroll change listener helps me?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem while detecting the scrolling data using ScrollChangeListener.

Yes, as does focus listener depending on how you decide to manage this.

 

arkadyz comments suggest how to do this using scrollChangeListener. 

 

Be aware that this is not trivial to do.  There are complications like getting off the event thread, making sure you only initiate the process once, handling network errors and so on.  You need to think through your design carefully.

 

But scroll change listener can work for you. 

Super Contributor
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: Problem while detecting the scrolling data using ScrollChangeListener.

Thank you peter.

Super Contributor
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: Problem while detecting the scrolling data using ScrollChangeListener.

Hi Friends,

 

i am added 10 to 15 fields to the screen when i scroll down it won't detect the scrollChanged method.

 

Can you please help me.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem while detecting the scrolling data using ScrollChangeListener.

[ Edited ]

Just to confirm, you added the listener to the Manager that contains these Fields and the scroll for that Manager is actually changed? 

 

Remember you won't get scroll change just as you go down the page, you will get it when the page top changes, so basically when you scroll off the page. 

Super Contributor
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: Problem while detecting the scrolling data using ScrollChangeListener.

Hi Peter,

 

yes i added the fields to that manager where i implemented the scrollchange listener.

 

and when i down the page i saw the componenets but it won't detect the scroll changed method. i added this manager to the screen.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem while detecting the scrolling data using ScrollChangeListener.

OK create a simple test MainScreen, add loads of LabelFields in a loop to a VerticalFieldManager, add the VFM to the screen, set the scroll change listener on the VFM and test that.  You should be able to get that down to about 30 lines of code.  If that doesn't work for you then paste it in here and then we have something to review and perhaps test ourselves.