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
Kaz32
Posts: 236
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel

What is the Event on ListView if scroll change

Hi, I'm using listView with listItem is one whole screen / page and use leftToRight orientation.

 

I want to know if user swipe to right / left and get the item data, ex: title on item.

(I want to add action item on page which is dynamic to the listview item)

What is the event?

 

I try use onActivationChanged, but user must click once first on listview item -> to get the item data

 

How to do this?

 

Thanks

Please use plain text.
Developer
SumiGhosh
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380
My Carrier: Vodafone

Re: What is the Event on ListView if scroll change

Chk onListItemProvider()
Please use plain text.
Developer
Kaz32
Posts: 236
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel

Re: What is the Event on ListView if scroll change

hi, thanks for your suggestion.

 

I try using 

onListItemProviderChanged: (on myListview)

 

I set breakpoint and debug it, but when I swipe right / left on listview the event not called / not stop on breakpoint.

 

So still need the event that detect listview swipe / scroll.

 

Thanks

Please use plain text.
Developer
Zmey
Posts: 1,510
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: What is the Event on ListView if scroll change

[ Edited ]

Hi,

 

You can use ListScrollStateHandler to determine firstVisibleItem's indexPath:

http://developer.blackberry.com/cascades/reference/bb__cascades__listscrollstatehandler.html

But I suspect it will always be the left item during scrolling.

 

It would be better to set the item which occupies the largest part of the screen as active item. Most likely this can be done by attaching LayoutUpdateHandlers to ListItemComponents and calculating their visible width based on layoutFrame's x. If the item occupies more than half of the screen, set it as active item (if it wasn't active yet).

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
Kaz32
Posts: 236
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel

Re: What is the Event on ListView if scroll change

Hi Zmey,

 

I try using ListScrollStateHandler and using onFirstVisibleItemChanged -> can detect swipe, so if user swipe right / left it call.

 

But I don't know how to get indexPath / currentIndex of listItem, when I check on firstVisibleItem -> it always 0 (not contain anything)

 

Using onScrollingChanged also can detect if stop swiping, but also I cannot determine the indexPath / currentIndex.

 

Any idea how to get this indexPath?

 

Thanks

Please use plain text.
Developer
Kaz32
Posts: 236
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel

Re: What is the Event on ListView if scroll change

Hi Zmey thanks for your reply

 

Here is my listView code

ListView {
		        id: detailNewsListView  
		        dataModel: detailNewscpp
                preferredWidth: screenWidthDetail
                horizontalAlignment: HorizontalAlignment.Center  
                layout: StackListLayout {
                    orientation: LayoutOrientation.LeftToRight
                    }
                flickMode: FlickMode.SingleItem
                scrollIndicatorMode: ScrollIndicatorMode.None
                
                property variant navigate: navigation
                property string type: channelType
            
                function relatedDataModel(aList) {
                    return detailNewscpp.createDataModel2(aList);
                }
	    	                
	    	    function setHeaderText(aPosCount) {
                    headerDetailNews.text = aPosCount;
                }
	    	    
                listItemComponents: [
	                ListItemComponent {
						DetailNewsItem {  // Whole page / screen item ListView
						    id: detailNewsItem
                        }
	                }    // ListItemComponent
	            ]    
                
                onActivationChanged: {  // can do, but user must click once first
                    var chosenItem = dataModel.data(indexPath);
                    shareMessage = chosenItem.shareMessage;
                }

                attachedObjects: [
                    ListScrollStateHandler {
                        id: handler
                        onFirstVisibleItemChanged: {  // If user swipe right / left this event called, but I dont know how to get indexPath / currentIndex
                            if (firstVisibleItem.length > 0) {
                                var chosenItem = dataModel.data(firstVisibleItem);
                                shareMessage = chosenItem.shareMessage;
                            }
                        }
                    }
                ]
            
            }    // ListView

 

onFirstVisibleItemChanged -> firstVisibleItem -> 0, no item

I cannot get the indexPath / currentIndex

 

I want make share action item, dynamic to item listView.

 

 

Thanks

Please use plain text.