-
-
Save devluis/6926963 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
Ti.UI.backgroundColor = '#dddddd'; | |
var url = "https://raw.github.com/appcelerator/Documentation-Examples/master/HTTPClient/data/json.txt"; | |
var win = Ti.UI.createWindow(); | |
var table = Ti.UI.createTableView(); | |
var tableData = []; | |
var json, fighters, fighter, i, row, nameLabel, nickLabel; | |
var xhr = Ti.Network.createHTTPClient({ | |
onload: function() { | |
// Ti.API.debug(this.responseText); | |
json = JSON.parse(this.responseText); | |
for (i = 0; i < json.fighters.length; i++) { | |
fighter = json.fighters[i]; | |
row = Ti.UI.createTableViewRow({ | |
height:'60dp' | |
}); | |
nameLabel = Ti.UI.createLabel({ | |
text:fighter.name, | |
font:{ | |
fontSize:'24dp', | |
fontWeight:'bold' | |
}, | |
height:'auto', | |
left:'10dp', | |
top:'5dp', | |
color:'#000', | |
touchEnabled:false | |
}); | |
nickLabel = Ti.UI.createLabel({ | |
text:'"' + fighter.nickname + '"', | |
font:{ | |
fontSize:'16dp' | |
}, | |
height:'auto', | |
left:'15dp', | |
bottom:'5dp', | |
color:'#000', | |
touchEnabled:false | |
}); | |
row.add(nameLabel); | |
row.add(nickLabel); | |
tableData.push(row); | |
} | |
table.setData(tableData); | |
}, | |
onerror: function(e) { | |
Ti.API.debug("STATUS: " + this.status); | |
Ti.API.debug("TEXT: " + this.responseText); | |
Ti.API.debug("ERROR: " + e.error); | |
alert('There was an error retrieving the remote data. Try again.'); | |
}, | |
timeout:5000 | |
}); | |
xhr.open("GET", url); | |
xhr.send(); | |
win.add(table); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment