I asked a similar question and got answer to it, now i come to another bump in the road. I am basically trying to get first the county names in an tableview, and then when i press on a county, all the cities that are in that county should create a tableview, and then all the company that is in that city should appear in a tableview, and the finally a window with some detail about the company. Here is my code:
Best regards! Filip
XML Code:
<?xml version="1.0" encoding="UTF-8"?>
<food_company>
<county>
<countyname>New York</countyname>
<city>
<cityname>New York City</cityname>
<restaurant>
<name>Dinos pizzeria</name>
<phone>01111111</phone>
<location>broadway1</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria2</name>
<phone>01111111</phone>
<location>broadway2</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria3</name>
<phone>01111111</phone>
<location>broadway3</location>
</restaurant>
</city>
<countyname>Baldwin County</countyname>
<city>
<cityname>Bay Minette</cityname>
<restaurant>
<name>Dinos pizzeria</name>
<phone>01111111</phone>
<location>broadway1</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria2</name>
<phone>01111111</phone>
<location>broadway2</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria3</name>
<phone>01111111</phone>
<location>broadway3</location>
</restaurant>
</city>
</lan>
</food_company>
app.js Code:
Titanium.UI.setBackgroundColor('#E1E6EE');
// create base UI tab and root window
var win1 = Titanium.UI.createWindow({
statusBarStyle: Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
tintColor: '#FFF',
backgroundColor:'#E1E6EE',
url: 'lan.js',
tabBarHidden: true,
navBarHidden: true
});
win1.open();
county.js Code:
Ti.include('app_functions.js');
var win = Titanium.UI.currentWindow;
// create a table to display news feeds--------------------------------
var itemsTable = Ti.UI.createTableView({
top : '11%',
left : 0,
leftImage : 'taxi.png',
backgroundColor : '#DCEEDC', //E1E6EE
bottom : '0%',
// search : searchBar,
filterAttribute : 'searchFilter'
});
win.add(itemsTable);
// define xmlFeed (you can customize this with any RSS feed)
var xmlFeed = 'http://eventverket.nu/test/test5.xml';
//'http://83.254.164.137:1000/test.xml';
// create a new HTTP client object
var xhr = Ti.Network.createHTTPClient();
// this method will process the remote data
xhr.onload = function() {
// create an xml object
var xml = this.responseXML;
// create an array that will store news items for our tableView
var data = [];
var data = [];
var items = xml.documentElement.getElementsByTagName("county");
for (var i=0; i<items.length; i++) {
var row = Ti.UI.createTableViewRow({
title: items.item(i).getTextContent()
});
data.push(row);
}
itemsTable.data = data;
// when the user clicks on a row
itemsTable.addEventListener('click', function(e) {
// NEW WINDOW
var newWindow = Titanium.UI.createWindow({
backgroundColor : '#DCEEDC', //E1E6EE
statusBarStyle : Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
font : fonts[16]['normal'],
url : "stad.js",
//backButtonTitle: 'Back',
//title: e.source.title,
tabBarHidden : true,
navBarHidden : true,
tintColor : '#FFF'
});
newWindow.open();
});
};
// this method will be called if there is an error in accessing the data
xhr.onerror = function() {
// hide activity indicator
activityIndicator.hide();
// display error
alert(this.status + ': ' + this.statusText);
return false;
};
// open the remote feed
xhr.open('GET', xmlFeed);
// execute the call to the remote feed
xhr.send();
city.js Code:
Ti.include('app_functions.js');
var newWin = Titanium.UI.currentWindow;
// create a table to display news feeds--------------------------------
var itemsTable = Ti.UI.createTableView({
top : '11%',
left : 0,
leftImage : 'taxi.png',
backgroundColor : '#DCEEDC', //E1E6EE
bottom : '0%',
// search : searchBar,
filterAttribute : 'searchFilter'
});
win.add(itemsTable);
// define xmlFeed (you can customize this with any RSS feed)
var xmlFeed = 'http://eventverket.nu/test/test5.xml';
//'http://83.254.164.137:1000/test.xml';
// create a new HTTP client object
var xhr = Ti.Network.createHTTPClient();
// this method will process the remote data
xhr.onload = function() {
// create an xml object
var xml = this.responseXML;
// create an array that will store news items for our tableView
var data = [];
var items = xml.documentElement.getElementsByTagName("city");
for (var i=0; i<items.length; i++) {
var row = Ti.UI.createTableViewRow({
title: items.item(i).getTextContent() //
});
data.push(row);
}
itemsTable.data = data;
// when the user clicks on a row
itemsTable.addEventListener('click', function(e) {
// NEW WINDOW
var newWindow = Titanium.UI.createWindow({
backgroundColor : '#DCEEDC', //E1E6EE
statusBarStyle : Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
font : fonts[16]['normal'],
url : "stad.js",
//backButtonTitle: 'Back',
//title: e.source.title,
tabBarHidden : true,
navBarHidden : true,
tintColor : '#FFF'
});
});
};
// this method will be called if there is an error in accessing the data
xhr.onerror = function() {
// hide activity indicator
activityIndicator.hide();
// display error
alert(this.status + ': ' + this.statusText);
return false;
};
// open the remote feed
xhr.open('GET', xmlFeed);
// execute the call to the remote feed
xhr.send();