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
Contributor
bit-brad
Posts: 31
Registered: ‎11-02-2012
My Device: Dev Alpha
Accepted Solution

Listview within Scrollview causes near infinite scrolling

I have a view that needs a Container("Content"), and then a ListView("Related Content"). I make the whole thing scrollable by embedding them both in a scrollview.

 

This behaves exactly as i'd expect, except that it continues to scroll past the ListView, and into nothing. Can I have a listview embedded in a scrollview without this happening? Or should I make a single ListView and provide a ListItemProvider, that defines a different container for the first item than the related content? It seems very complicated to implement a ListItemProvider just to fix this scrolling issue.

Please use plain text.
Contributor
bit-brad
Posts: 31
Registered: ‎11-02-2012
My Device: Dev Alpha

Re: Listview within Scrollview causes near infinite scrolling

[ Edited ]

I solved it. When the ListView is populated, I set the preferredHeight of the ListView to:

 

( height of content row + content padding ) * count of entires in ListView

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

Re: Listview within Scrollview causes near infinite scrolling

Hi, I'm also using listView within scrollView and cause this problem.

 

I have difficulty to determine list item height, because its contain a multiline label (text from webservice) -> don't know the height

How to determine list item height if there is a multiline label?

 

Thanks

Please use plain text.
Contributor
bit-brad
Posts: 31
Registered: ‎11-02-2012
My Device: Dev Alpha

Re: Listview within Scrollview causes near infinite scrolling

A co-worker of mine had the same issue. I'll ask her Monday to confirm, but I believe she added a onLayoutChanged signal handler to each row item. When this is called, you can get the actual height of the row, and keep track of the total height as each one is called.
Please use plain text.
Developer
nareshkodumuri
Posts: 125
Registered: ‎04-28-2012
My Device: BlackBerry 9800

Re: Listview within Scrollview causes near infinite scrolling

Hi,

 

 

       I am also facing the same problem, I don't have the exact height of the list item because it depends on the data coming from the service. Anyone please provide me the solution.

 

 

Regards,

Naresh Kodumuri.

Please use plain text.
Developer
urbanglowcam
Posts: 148
Registered: ‎10-30-2010
My Device: Bold 9930

Re: Listview within Scrollview causes near infinite scrolling

I also have the same issue now since I have to provide support for the Q10 display. Basically, I had a PreferredHeight before the Q10 was in the picture, so the sizing was just right. Now that I have to put it into consideration, there is a huge space under the ListView for the Q10 version of my app since it has to compensate for the Z10.

 

Is there a way where I don't have to use a PreferredHeight that is fixed and can do this so that it scales nicely depending on the elements in the ListView? Like the others, if I remove the PreferredHeight, it will scroll endlessly and ruin the experience.

 

Thanks

Please use plain text.
Contributor
bit-brad
Posts: 31
Registered: ‎11-02-2012
My Device: Dev Alpha

Re: Listview within Scrollview causes near infinite scrolling

Best thing to do is scrap embedding a listview in a scrollview, make the whole view 1 single listview, with a header view as the first item that is different than the rest of the rows. Now you can make the rows varible height. Make sense?

Please use plain text.
Developer
urbanglowcam
Posts: 148
Registered: ‎10-30-2010
My Device: Bold 9930

Re: Listview within Scrollview causes near infinite scrolling

Can you still add elements like images and segment controllers around the List View with that method bit-brad? Or are you more limited?
Please use plain text.
Contributor
bit-brad
Posts: 31
Registered: ‎11-02-2012
My Device: Dev Alpha

Re: Listview within Scrollview causes near infinite scrolling

Yep you can add anything you want. 

 

So, when you define your ListView in QML, you want to look at the following itemType function... I've setup a very simple sample below. Hope it helps.

 

ListView {

    dataModel: XmlDataModel {

        source: "model.xml"

    }

    function itemType(data, indexPath) {

        return (indexPath.length == 1 ? 'header' : 'item');

    }

    listItemComponents: [

        ListItemComponent {

            type: "header"

            SegmentedControl {

                /* ... */

            }

        },

        ListItemComponent {

            type: "item"

            /* row definition here */

            Label {

                

            }

            /* ... */

        }

    ]

}

 
Please use plain text.
Developer
urbanglowcam
Posts: 148
Registered: ‎10-30-2010
My Device: Bold 9930

Re: Listview within Scrollview causes near infinite scrolling

Thanks bit-brad. I tried this and couldn't get an ImageView to work. The only part I don't understand is the code

 

    function itemType(data, indexPath) {

        return (indexPath.length == 1 ? 'header' : 'item');

 

I can't get any other QML property to show in a ListView. It always looks like a standard list. I'm not sure what I'm doing wrong.

Please use plain text.