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

Native Development

Reply
Developer
helex
Posts: 253
Registered: ‎02-14-2012
My Carrier: -
Accepted Solution

ListView - which items are currently visible?

Hi!

 

I were unable to find a method how to check which elements of a listview are currently visible at the screen and which are hidden. Is there since the Beta3 a method or is this scheduled for the Beta4?

 

The  scrollToItem and  scrollToPosition are since the Beta3 implemented. But how to read out this data?

 

Any ideas?

Please use plain text.
Developer
peter9477
Posts: 6,447
Registered: ‎12-08-2010
My Carrier: none

Re: ListView - which items are currently visible?

Those two routines work to change the scroll position, but they cannot report it.

See this thread where the question's basically been asked (and only partially answered) before: http://supportforums.blackberry.com/t5/Cascades-Development/Is-there-a-way-to-get-the-scroll-positio...

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
helex
Posts: 253
Registered: ‎02-14-2012
My Carrier: -

Re: ListView - which items are currently visible?

Thanks for the link, I were unable to get it working so far. Again very frustraiting but I will try it tomorrow again. 

 

Is a counterpart to scrollToItem announced for the Beta4? I can't find any information regarding this.

 

I don't know for what scrollToItem could be useful for if you are unable to store where in the list you were the last time. :smileyindifferent:

Please use plain text.
Developer
peter9477
Posts: 6,447
Registered: ‎12-08-2010
My Carrier: none

Re: ListView - which items are currently visible?

scrollToItem() is useful in several situations, including when you want to scroll to a newly added item which may be elsewhere in the list than the currently visible region.

You can also use it to approximate the "restore previous position", in a crude manner, if the user had a particular list item selected. That is, while you can't easily know whether that item was in-view at the time, the user would probably be more than happy if you were (upon restart of the app) to restore the selection and scroll the list to display the selected item.

Nothing has been announced for Beta 4 except the items listed in the roadmap, and this isn't included. I hope someone has checked for this as a feature request in Jira, and created a ticket if there was none.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
helex
Posts: 253
Registered: ‎02-14-2012
My Carrier: -

Re: ListView - which items are currently visible?

Jira? Is this only for BB employee or could I create a ticket myself over there? :smileyhappy:

 

I need to know the current list position without selecting a item before. Thats the problem. My items are not selectable and I need to apply a function depending of the currently visible item.

 

And additional to the function I'm currently working on I need to restore the last position in the list after a restart of my application. So I need to know the position for two functions of my app. 

Please use plain text.
Developer
peter9477
Posts: 6,447
Registered: ‎12-08-2010
My Carrier: none

Re: ListView - which items are currently visible?

It's for all of us non-RIM developers; RIM has their own internal system for tracking issues.

Look for the "Developer Issue Tracker" link at the bottom of https://developer.blackberry.com/ in the Support section, or try going directly there with this link: https://www.blackberry.com/jira/secure/Dashboard.jspa

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
helex
Posts: 253
Registered: ‎02-14-2012
My Carrier: -

Re: ListView - which items are currently visible?

Okay, I found a issue at the issue tracker for this problem: ListView should support a way to know its current scroll position

 

Please Vote!

 

Hm... not sure how I should now proceed at my own project. Should I continue to use ListView and hope for a API update before the BB10 release to get able to publish my application before the start or should I try to integrate my own solution using several dynamically loaded Container {} and create my own application UI logic. :smileysad:

Please use plain text.
Developer
peter9477
Posts: 6,447
Registered: ‎12-08-2010
My Carrier: none

Re: ListView - which items are currently visible?

I wouldn't try to reproduce a ListView out of raw materials (so to speak) if I were you.

I'm pretty confident I can use the pieces I mentioned in that other thread to work around the lack of an API for this actually. Especially if you're working with a list with consistently sized list items...

I just won't have time to put together a proof of concept for at least another week. It's a good opportunity for some enterprising young whipper-snapper to try beating me to it though! ;-)

(Thanks for digging up that link... I voted. Devs really need to put in a bit of elbow grease on this sort of thing if we want things to keep improving.)

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
helex
Posts: 253
Registered: ‎02-14-2012
My Carrier: -

Re: ListView - which items are currently visible?

Okay, after sleeping a night over it I retried it with your approach a second time. 

 

Thats my solution for a horizontal scrolling list view in which every element in the list is exactly as big as the screen, so there is always only a single element which is the most visible item in the list:

 

listItemComponents: [
    ListItemComponent {
		type: "item"
		Container {
			attachedObjects: LayoutUpdateHandler {
				id: luhPosition
				onLayoutFrameChanged: {
					lblTest.text = "XXX" + luhPosition.layoutFrame.x + " - " + Qt.pageHandler.layoutFrame.width
					if (luhPosition.layoutFrame.x >= - Qt.pageHandler.layoutFrame.width / 2 && luhPosition.layoutFrame.x <= Qt.pageHandler.layoutFrame.width / 2) {
						//call here a C++ routine to deliver the ID of the currently visible panel in the ListView:
						
						testArea.background = Color.Blue
			   
					} else {
						testArea.background = Color.DarkRed
					}
				}
			}
		}
		Container {
			preferredHeight: Qt.pageHandler.layoutFrame.height
			preferredWidth: Qt.pageHandler.layoutFrame.width
			background: Color.Green
			id: testArea
			Label {
				id: lblTest
				text: "Test"
			}
		}
	}
]

 

 

I created a second LayoutUpdatehandler at the root container in which my ListView is embedded to get the screen resolution and provide the Object inside the Listview using:

 

onCreationCompleted: {
    Qt.pageHandler = pageHandler;
}

 

 

Please use plain text.