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
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Adding Dynamic Custom components - Crashes my App

[ Edited ]

Hi all,

 

I have a list of Users. 

On Row Click I show UserDetail, this detail is fetched from Server as JSON. My CPP Code looks like this :

 

void DirectoryDetail::loadDetailData(NavigationPane *root, QString userId) {
	busyIndicator = page->findChild<ActivityIndicator*>("busyIndicator");
	//start indicator
	setIndicator(true);
	DirectoryRequest* dRequest = new DirectoryRequest();
	dRequest->loadDetailData(userId);
	connect(dRequest, SIGNAL(complete(QString, bool)), this, SLOT(renderData(QString, bool)));
	root->push(page);
}

void DirectoryDetail::renderData(QString info, bool success) { bb::data::JsonDataAccess jda; QVariant results = jda.loadFromBuffer(info); if(results.canConvert(QVariant::Map)){ QVariantMap dataMap = results.toMap(); QVariant entryvar = dataMap.value("entry"); if(entryvar.canConvert(QVariant::Map)){ QVariantMap directoryMap; directoryMap = entryvar.toMap(); Label *name = page->findChild<Label*>("name"); name->setText(directoryMap.value("name").toMap().value("firstName").toString()+" "+directoryMap.value("name").toMap().value("lastName").toString()); QVariantList phoneList = directoryMap.value("phoneNumbers").toList(); if(phoneList.size()>0) { setPhoneNumbers(phoneList); } setIndicator(false); } } }

void DirectoryDetail::setPhoneNumbers(QVariantList phoneList) { QmlDocument* header = QmlDocument::create().load("TypeValueList.qml"); Container* c = header->createRootNode<Container>(); ListView *list = header->findChild<ListView*>("typeValuelist"); GroupDataModel *model = new GroupDataModel(QStringList() <<"Phone"); model->setGrouping(ItemGrouping::None); for (QList<QVariant>::iterator it = phoneList.begin(); it != phoneList.end(); it++){ QVariantMap phoneMap = it->toMap(); iterateMap(phoneMap); model->insert(phoneMap); } list->setDataModel(model); qDebug()<<"---------------setPhoneNumbers-------------Code Never reaches here-----------"; list->setVisible(true); list->setEnabled(true); page->setContent(c); }

 

TypeValueList.qml - This is a custom QML. It consists of a ListView with ListItemComponent as a container of 2 labels. ListView dataModel is set as :

 

 

-----------------------------

 | Label1 |      | Label2 |

-----------------------------

 

ListView {
		id: typeValuelist
		objectName: "typeValuelist" 
		enabled:false
		visible: false
		dataModel: GroupDataModel {
		}

	listItemComponents: [
		ListItemComponent{
			type: "item"
		}
		Container {//my container
		
		 Label {
			   id:typeLabel
			   text: ListItemData.Type
		   }
		    Label {
			   id:valueLabel
			   text: ListItemData.Value
		   }
		}
	]
}

 

Am I doing something here in a wrong way?

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: Adding Dynamic Custom components - Crashes my App

Its a quite common task.. I guess many developers have alreday done this  here.. But its sad to see that nobody interested in helping others..

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: Adding Dynamic Custom components - Crashes my App

The foremost problem that I found is in your Qml file.

 

The placement of Container is out of the  ListViewComponent . It should be inside the ListViewComponent like this.

 

ListView {
		id: typeValuelist
		objectName: "typeValuelist" 
		enabled:false
		visible: false
		dataModel: GroupDataModel {
		}

	listItemComponents: [
		ListItemComponent{
			type: "item"
                        Container {//my container
		
		 Label {
			   id:typeLabel
			   text: ListItemData.Type
		   }
		    Label {
			   id:valueLabel
			   text: ListItemData.Value
		   }
		}
	    }
		
	]
}

 

 Make changes. Hope It's this.

 

 

 

 

Always Success
Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: Adding Dynamic Custom components - Crashes my App

First of all thanks for taking interest. The actual code for QML is : 

 

import bb.cascades 1.0

Container  //list Container starts
{
   property alias titleText : listHeader.text
   
   layout: StackLayout {
        layoutDirection: LayoutDirection.TopToBottom
   } 
    layoutProperties: StackLayoutProperties {
        horizontalAlignment: HorizontalAlignment.Fill
        verticalAlignment: VerticalAlignment.Fill
    }  
	 ListView {
		id: typeValuelist
		objectName: "typeValuelist" 
		enabled:false
		visible: true
		dataModel: GroupDataModel {
		}
		listItemComponents: [
            ListItemComponent{
                type: "item"
               /* TypeValueItem{
                }*/
                    Container {
                       layout: StackLayout {
                           layoutDirection: LayoutDirection.TopToBottom
                       }
                        Label {
                               id:descLabel
                               text: ListItemData.Type//type
                               textStyle {
                                   base: SystemDefaults.TextStyles.SmallText
                                   fontWeight: FontWeight.Bold
                                   color: Color.create ("#FBB917")
                               }
                           }
                           Divider {
                               layoutProperties: StackLayoutProperties {
                                  verticalAlignment: VerticalAlignment.Fill
                                 }
                           }
                            Label {
                              id:dateLabel
                              text: ListItemData.Value//value
                              textStyle {
                                  base: SystemDefaults.TextStyles.SmallText
                                  fontWeight: FontWeight.Normal
                                  color: Color.create ("#FFFFFF")
                              }
                          }
                        Divider {
                             layoutProperties: StackLayoutProperties {
                                horizontalAlignment: HorizontalAlignment.Fill
                            }
                         }
                     }
            }
        ]
	   onSelectionChanged: {
			if (selected) {
			}
	   }
   }//listView Ends
   Divider {
   }
}//list Container ends

 

 

 

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Highlighted
Developer
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer
My Carrier: relience

Re: Adding Dynamic Custom components - Crashes my App

function itemType(data, indexPath) {
return "item";
}

I think you are missing this function in the listview.
Please make changes and try again.