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
level32
Posts: 52
Registered: ‎03-29-2012
My Device: Playbook, Dev Alpha
Accepted Solution

Coming from Android, is there a something similar to LayoutInflater?

I was thinking of extending Page and "inflating" the page with a QmlDocument in the constructor. Is this possible?  

Here's a sample:

PageBase::PageBase(const QString & qmlFile, QObject * app): Page(app)
{
	QmlDocument *qml = QmlDocument::create(qmlFile);
	qml->setContextProperty("page", this);
	qml->setContextProperty("app", app);

	//TODO: set this page's content with the qml
        //???????
}

 

 

Please use plain text.
Developer
blackqtcoder
Posts: 146
Registered: ‎05-18-2012
My Device: PlayBook & STL100-1 LE Z10 & Dev Alpha C

Re: Coming from Android, is there a something similar to LayoutInflater?

You can extending Page ( I do, too), but I create QmlDocument from app.cpp file. I don't tested if it's possible doing this inside unique class.

---------------------------------------------------------------
Leandro Cerdan - Duantox Apps
BlackBerry Elite dev
TapyHold, Built for Blackberry multimedia scrapbook
Please use plain text.
Developer
level32
Posts: 52
Registered: ‎03-29-2012
My Device: Playbook, Dev Alpha

Re: Coming from Android, is there a something similar to LayoutInflater?

How do you set the QmlDocument to your extended Page?
Please use plain text.
Developer
blackqtcoder
Posts: 146
Registered: ‎05-18-2012
My Device: PlayBook & STL100-1 LE Z10 & Dev Alpha C

Re: Coming from Android, is there a something similar to LayoutInflater?

I use extended Page as an object element in QmlDocument.

QmlDocument is declared in app.cpp file created with bb10 Sdk

---------------------------------------------------------------
Leandro Cerdan - Duantox Apps
BlackBerry Elite dev
TapyHold, Built for Blackberry multimedia scrapbook
Please use plain text.
Developer
level32
Posts: 52
Registered: ‎03-29-2012
My Device: Playbook, Dev Alpha

Re: Coming from Android, is there a something similar to LayoutInflater?

I see. I guess you don't get a preview in Design Mode then. I'd like to avoid this.
Please use plain text.
Developer
blackqtcoder
Posts: 146
Registered: ‎05-18-2012
My Device: PlayBook & STL100-1 LE Z10 & Dev Alpha C

Re: Coming from Android, is there a something similar to LayoutInflater?

[ Edited ]

I develop with Linux version of Sdk which doesn't support Qml preview at this moment. 

Because I have a devalpha device don't worry me.

---------------------------------------------------------------
Leandro Cerdan - Duantox Apps
BlackBerry Elite dev
TapyHold, Built for Blackberry multimedia scrapbook
Please use plain text.
Developer
level32
Posts: 52
Registered: ‎03-29-2012
My Device: Playbook, Dev Alpha

Re: Coming from Android, is there a something similar to LayoutInflater?

I tried this: 

 

PageBase::PageBase(const QString & qmlFile, QObject * app): Page(app)
{
	QmlDocument *qml = QmlDocument::create(qmlFile);
	qml->setContextProperty("page", this);
	qml->setContextProperty("app", app);

	Page * page = m_qmlDoc->createRootNode<Page>();
	setContent(page->content());
}

The page shows up, but there's no content.

Please use plain text.
Developer
Pallam_Madhukar
Posts: 21
Registered: ‎04-26-2012
My Device: BlackBerry 9800

Re: Coming from Android, is there a something similar to LayoutInflater?

you can achive this simplly in QML

 

Example: A Listfiew inflating a custom component into main screen

 

File 1: main.qml

import bb.cascades 1.0

Page {
    content: Container {
        background: Color.create ("#ffBBCCFA")
        ListView {
            dataModel: XmlDataModel {
                source: "models/employees.xml"
            }
            listItemComponents: [
                ListItemComponent {
                    type: "employee"
                   ImageListItem {/*This is the another XML file, it is just like Inflating another screen, and ImageListItem is ImageListItem.qml(customcomponent)*/ }
                }
            ]
        }
    }
}

 File 2: ImageListItem.qml(Custom Component)

/*
This is custom component for list
It is structure of List Item
*/


import bb.cascades 1.0

Container {
    minWidth: 768
    maxWidth: 1280
    Container {
        layout: StackLayout {
            layoutDirection: LayoutDirection.LeftToRight
        }
        layoutProperties: StackLayoutProperties {
            verticalAlignment: VerticalAlignment.Center
        }
        ImageView {
            minWidth: 100
            imageSource: "asset:///images/india.png"    
        }
        Label {
            text: ListItemData.name //"Pallam Madhukar"
            textStyle.color: Color.DarkBlue
            minWidth: 550
            layoutProperties: StackLayoutProperties {
                verticalAlignment: VerticalAlignment.Center
            }
        }
       
    }
    Divider {
        opacity: 5.0
    }
}

 File3: employee.xml(Data model)

<root>
	<employee name="PallamMadhukar" job="BB10 Developer" salary="1000000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Pallam Madhukar" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="PallamMadhukar" job="BB10 Developer" salary="1000000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Pallam Madhukar" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="PallamMadhukar" job="BB10 Developer" salary="1000000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Pallam Madhukar" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="PallamMadhukar" job="BB10 Developer" salary="1000000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Pallam Madhukar" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="PallamMadhukar" job="BB10 Developer" salary="1000000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Pallam Madhukar" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="PallamMadhukar" job="BB10 Developer" salary="1000000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Pallam Madhukar" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Kodumori Naresh" job="BB10 Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Uma Venkateshwarlu" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="RVN Sarvesh" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Anabothula Raju" job="BB Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Venkateshwrlu" job="Android Developer" salary="10000.00" age="" experiance="0.5"/>
	<employee name="Prashu Kesarawani" job="DotNET Developer" salary="10000.00" age="" experiance="0.5"/>
</root>

 Place these files in assets folder:

assets/main.qml

assets/ImageListItem.qml

assets/models/employees.xml

 

 

Please use plain text.
Developer
level32
Posts: 52
Registered: ‎03-29-2012
My Device: Playbook, Dev Alpha

Re: Coming from Android, is there a something similar to LayoutInflater?

Not entirely what I meant. I'm trying to create a Page in C++. It'll have common actions and stuff that I need accross the application. I want to load a QmlDocument into said Page. 

Please use plain text.
Developer
Pallam_Madhukar
Posts: 21
Registered: ‎04-26-2012
My Device: BlackBerry 9800

Re: Coming from Android, is there a something similar to LayoutInflater?

[ Edited ]

Can you explain complete requirement?

Please use plain text.