12-01-2012 02:50 AM
Hi,
When I am using DataSource for loading XML, the listview shows the data only if there is atleast 2 item in the XML.
import bb.cascades 1.0
import bb.data 1.0
NavigationPane {
id: nav
Page {
id: emp
titleBar: TitleBar {
visibility: ChromeVisibility.Visible
}
onCreationCompleted:
{
dataSource1.load(); //load the xml when page is created
}
actions: [
ActionItem {
title: qsTr("Create List")
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
dialog.open();
}
}
]
Container {
topPadding: 30.0
leftPadding: 20.0
rightPadding: 20.0
ListView {
id:list1
dataModel:dataModel
listItemComponents: [
ListItemComponent {
StandardListItem {
title: {
qsTr(ListItemData.name)
}
}
}
]
}
}
} //page
attachedObjects: [
GroupDataModel {
id:dataModel
},
DataSource {
id: dataSource1
source: "models/employeelist.xml"
query: "/root/employee"
type: DataSourceType.Xml
onDataLoaded: {
dataModel.clear();
dataModel.insertList(data);
}
},
Dialog {
id: dialog
Container {
background: Color.Gray
layout: StackLayout {
}
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
preferredWidth: 700.0
leftPadding: 20.0
rightPadding: 20.0
topPadding: 20.0
bottomPadding: 20.0
Container {
background: Color.White
horizontalAlignment: HorizontalAlignment.Center
preferredWidth: 700.0
preferredHeight: 50.0
Label {
text: "Add Employee List"
textStyle.base: SystemDefaults.TextStyles.TitleText
textStyle.color: Color.DarkBlue
horizontalAlignment: HorizontalAlignment.Center
textStyle.fontSizeValue: 4.0
}
}
Container
{
topPadding: 30.0
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
Label {
text: "Employee Name "
}
TextField {
id:nametxt
}
}
Container {
topPadding: 30.0
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
Button {
text: "OK"
onClicked:
{
var name=nametxt.text;
if(nametxt.text=="")
{
_model.toastinQml("Please enter a name");
}
else
{
_model.writeEmployeeName(name); //writing name to the employeelist.xml
nametxt.text="";
dialog.close();
dataSource1.load(); //loading the xml
}
}
preferredWidth: 300.0
}
Button {
text: "Cancel"
onClicked:
{
dialog.close();
}
preferredWidth: 300.0
}
}
}
}
]
}//navigation
When I add a name first time to the xml, the list shows nothing.Then when I add a name again, it displays the list.
Why is it so? Is there any mistake I have done?
Please Help!!
Thanks in Advance
Dhanya
Solved! Go to Solution.
01-13-2013 12:28 AM
01-21-2013 04:48 AM
I don't know the solution, but I can give you an hint: the problem comes from the query :
query: "/root/employee"
I had to parse an xml file manually and when the list has only one element, it is not longer recognise as a list by the XmlDataAccess.
Try with something like "/root/", but if it works, then it does not support multiple items anymore....
02-11-2013 09:40 PM - edited 02-11-2013 09:48 PM
Try setting the grouping property of the GroupDataModel to ItemGrouping::None. The GroupDataModel is mainly used for sorting data items by comparing the values of at least two items and accordingly sort them.
Samar Abdelsayed - Application Development Consultant - BlackBerry
Did this answer your quetion? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
02-24-2013 05:12 PM
Sorry for bumping old thread but how is it mark 'Solved'? ItemGrouping::None does not help me. If .xml has only one Item to show then this Item is not shown at all. Everything is ok when .xml has 2+ items.
04-11-2013 11:22 AM
I'm also having this problem. Would anyone be so kind in providing a solution?
04-19-2013 03:42 PM
It seems that this is a known issue reported on the DIT that has been escalated to BlackBerry's internal MKS defect tracking system. Until this issue is investigated by our internal teams, please use the workaround suggested by the reporter of the issue by introducing an "if" statement before insertinging the data to the DataModel:
if (data.name) {
empDataModel.insert(data);
} else {
empDataModel.insertList(data);
}
04-24-2013 05:50 PM