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

Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

ListItemComponent source

Hi, I've been trying to figure this one out and I had no luck..


So I have a page with ListView and two different ListItemComponents.


I am trying to use the same page in two separate tabs and simply choose ListItemComponent based on some variable defined in the page.


How would I go about doing this?

Twitter: @gyubok
Posts: 508
Registered: ‎01-19-2011
My Device: My Trusty Red Plane
My Carrier: Outer Space

Re: ListItemComponent source

normally, you define your list items for a listview like this


ListView {
                        id: listView

                        listItemComponents: [
                            ListItemComponent {
                                type: "listItem"
//+ definition

ListItemComponent {
type: "header"
//+ definition.

 each listItemComponent should have an own distinct type. You can use whatever string you want, as long as it is unique, even listItem1, listItem2, ...


Then, each listview can have this function

function itemType(data, indexPath) {
	return "listItem"; 

 Per default, it returns "header" and "listItem" if you are using a GroupDataModel, and "listItem" for ArrayDataModel (I think). What you should do is just overwrite the itemType function, e.g. like this:


function itemType(data, indexPath) {
    if (thisPageIsYourFirstTab) //you need to define this variable yourself
	return "listItem1";
        return "listItem2";

 and that should be it Smiley Happy


I'm a bird from outer space. But I'm not flappy o.o
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: ListItemComponent source

If you are trying to re-use components, creating your own custom component is pretty trival. You basically just put it in it's own QML file, and then you can use it wherever you like.


This lets you do something like you suggest: having the same ListView that's customized however you wanted, with a few properties you can tweek to get the proper behaviour for the specific case.




Paul Bernhardt
Application Development Consultant

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker