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
Charuta_Rajopadhye
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10
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::smileysurprised:nContainerOneSwiped(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::smileyvery-happy:efault) ;
qDebug() << "scrolled" ;
}
}
}

 

 

void Tour::smileysurprised:nContainerTwoSwiped(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::smileyvery-happy:efault) ;
}
else if(currentX < 0 && currentX * -1 > _dragThreshold)
{
qDebug() << "threshold crossed cont 2 right" ;
_scrollView->scrollToPoint(0, 768, ScrollAnimation::smileyvery-happy:efault) ;
}
}
}

 

void Tour::smileysurprised:nContainerThreeSwiped(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::smileyvery-happy:efault) ;
}
else if(currentX < 0 && currentX * -1 > _dragThreshold)
{
// Nothing to do.
}
}
}

Please use plain text.
Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

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.
Please use plain text.
Developer
Charuta_Rajopadhye
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10

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?

Please use plain text.
Developer
lildeimos
Posts: 58
Registered: ‎05-21-2012
My Device: DA C, Z10 LE

Re: Advice on scroll view

use layout

Please use plain text.
Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: Advice on scroll view

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

Re: Advice on scroll view

did it already, doesnt display!

 

this is my code:

 

ListView* SettingSummayControl::createListView() {
StackListLayout *s = StackListLayout::create().headerMode(ListHeaderMode::smileyfrustrated:ticky).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 ;
}

Please use plain text.
Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: Advice on scroll view

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

Re: Advice on scroll view

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

Please use plain text.
Developer
Charuta_Rajopadhye
Posts: 92
Registered: ‎08-01-2013
My Device: Z10, Q5, Q10

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!

Please use plain text.
Developer
lildeimos
Posts: 58
Registered: ‎05-21-2012
My Device: DA C, Z10 LE

Re: Advice on scroll view

have you tried to do ?

listView->setLayout(s)

 

Please use plain text.