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
Highlighted
Developer
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
My Carrier: Vodaphone
Accepted Solution

Advice on scroll view

Hi all,

 

i have a scroll view and 3 containers placed within, container 1, container 2 and container 3.

when i swipe right any, the next should be displayed.

and when i swipe left, previous should be displayed.

the containers are of screen size.

to i tried scrollToPoint() by 0, deviceWidth for 1st container, deviceWidth, 2*deviceWidth for second and so on, on their onTouch event.

but it does not work.. does any one have any ideas. 

Please help!

follows my code for onTouchEvents of containers:

 

void Tour:Smiley SurprisednContainerOneSwiped(bb::cascades::TouchEvent* touchEvent) {
static float dx = 0.0 ;
float currentX = 0.0 ;
if(touchEvent->isDown())
{
dx = touchEvent->localX() ;
}
else if(touchEvent->isMove())
{
currentX = (dx - (touchEvent->localX())) ;
if(currentX > _dragThreshold)
{
qDebug() << "threshold crossed cont 1" ;
_scrollView->scrollToPoint(0, 768, ScrollAnimation:Smiley Very Happyefault) ;
qDebug() << "scrolled" ;
}
}
}

 

 

void Tour:Smiley SurprisednContainerTwoSwiped(bb::cascades::TouchEvent* touchEvent) {
static float dx = 0.0 ;
float currentX = 0 ;
if(touchEvent->isDown())
{
dx = touchEvent->localX() ;
}
else if(touchEvent->isMove())
{
currentX = touchEvent->localX() - dx ;
if(currentX > 0 && currentX > _dragThreshold)
{
qDebug() << "threshold crossed left" ;
_scrollView->scrollToPoint(0, 768, ScrollAnimation:Smiley Very Happyefault) ;
}
else if(currentX < 0 && currentX * -1 > _dragThreshold)
{
qDebug() << "threshold crossed cont 2 right" ;
_scrollView->scrollToPoint(0, 768, ScrollAnimation:Smiley Very Happyefault) ;
}
}
}

 

void Tour:Smiley SurprisednContainerThreeSwiped(bb::cascades::TouchEvent* touchEvent) {
static float dx = 0.0 ;
float currentX = 0 ;
if(touchEvent->isDown())
{
dx = touchEvent->localX() ;
}
else if(touchEvent->isMove())
{
currentX = touchEvent->localX() - dx ;
if(currentX > 0 && currentX > _dragThreshold)
{
qDebug() << "threshold crossed left" ;
_scrollView->scrollToPoint(0, 768, ScrollAnimation:Smiley Very Happyefault) ;
}
else if(currentX < 0 && currentX * -1 > _dragThreshold)
{
// Nothing to do.
}
}
}

Developer
Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: Advice on scroll view

Can't answer your question directly, but you could try using a ListView instead, with these properties:

snapMode: SnapMode.LeadingEdge
flickMode: FlickMode.SingleItem

Turn your containers into a custom listItemCompent and size them so they fit the whole screen. I think that will get you the same effect with much less effort.
Developer
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
My Carrier: Vodaphone

Re: Advice on scroll view

i did implement a list, in cpp, but i want to scroll it horizontally, how shall i achive this? any ideas?

Developer
Posts: 77
Registered: ‎05-21-2012
My Device: DA C, Z10 LE, Passport
My Carrier: TIM

Re: Advice on scroll view

use layout

Developer
Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: Advice on scroll view

use the layout property to change it to a StackListLayout, with horizontal orientation.
Developer
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
My Carrier: Vodaphone

Re: Advice on scroll view

did it already, doesnt display!

 

this is my code:

 

ListView* SettingSummayControl::createListView() {
StackListLayout *s = StackListLayout::create().headerMode(ListHeaderMode:Smiley Frustratedticky).orientation(LayoutOrientation::LeftToRight); ;
// create list view.
ListView* listView = ListView::create().layout(s);
// create data provider for list view.
_listProvider = new SettingSummayListDataProvider() ;
// set data model in list view.
listView->setDataModel(_admListViewModel) ;
// set data provider in list view.
listView->setListItemProvider(_listProvider) ;
return listView ;
}

Developer
Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: Advice on scroll view

try mocking it up in qml... i've used this exact technique before and it works well.
Developer
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
My Carrier: Vodaphone

Re: Advice on scroll view

if i keep the orientation TopToBottom the list is displayed, but when i change it to leftToRight it disappers.

Developer
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
My Carrier: Vodaphone

Re: Advice on scroll view

moked it up in QML, it works in qml, in cpp i do not know what i m doing wrong!

Developer
Posts: 77
Registered: ‎05-21-2012
My Device: DA C, Z10 LE, Passport
My Carrier: TIM

Re: Advice on scroll view

have you tried to do ?

listView->setLayout(s)