Last active
August 29, 2015 14:03
-
-
Save philsmithsonuk/6afe59833daeef8f3f24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Placed in /lib/functions.js | |
var getData = function(callback){ | |
var rssFeed = Ti.Network.createHTTPClient(); | |
rssFeed.onload = function(){ | |
var xml = this.responseXML; | |
var items = xml.documentElement.getElementsByTagName("item"); | |
var _title = ""; | |
var tableData = []; | |
var row = ""; | |
var rowLbl = ""; | |
for(var i =0; i < items.length; i++) | |
{ | |
_title = items.item(i).getElementsByTagName("title").item(0).textContent; | |
//create row | |
row = Ti.UI.createTableViewRow({ | |
height: Ti.UI.SIZE, | |
guid: _guid | |
}); | |
//create label for row | |
rowLbl = Ti.UI.createLabel({ | |
text: _title, | |
textAlign: "center" | |
}); | |
//add label to row | |
row.add(rowLbl); | |
//add row to tableData array | |
tableData.push(row); | |
} | |
//call callback function, pass data | |
callback(tableData); | |
}; | |
rssFeed.onerror = function(e){ | |
Ti.API.info("Error getting data from URL: "+JSON.stringify(e)); | |
}; | |
rssFeed.open("GET", "http://blog.foolprooflabs.com/feed/"); | |
rssFeed.send(); | |
}; | |
exports.getData = getData; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var functions = require('functions'); | |
var tblView = Ti.UI.createTableView({ | |
backgroundColor: "red" | |
}); | |
//call getdata, passing callback function | |
$.btn_refresh.addEventListener('click', function(){ | |
functions.getData(function(data){ | |
tblView.data = data; | |
}); | |
}); | |
//add table view to window | |
$.parentContainer.add(tblView); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment