Skip to content

Instantly share code, notes, and snippets.

@KarthiPnsmy
Created October 18, 2013 17:18
Show Gist options
  • Save KarthiPnsmy/7044798 to your computer and use it in GitHub Desktop.
Save KarthiPnsmy/7044798 to your computer and use it in GitHub Desktop.
listing
var win = Ti.UI.createWindow({
backgroundColor : "#ccc"
});
var jsonData = {
"restaurants" : [{
"id" : 1,
"title" : "Patel Brother",
"image_url" : "appicon.png",
"address" : "8800 Sawmil road, Texas",
"tags" : ["indian", "asian"]
}, {
"id" : 2,
"title" : "Saravanabavan",
"image_url" : "appicon.png",
"address" : "7645 William road, NY",
"tags" : ["indian", "asian", "chinese"]
}, {
"id" : 3,
"title" : "Ahemad Brother",
"image_url" : "appicon.png",
"address" : "7675 Sawmil road, Texas",
"tags" : ["indian", "asian"]
}, {
"id" : 4,
"title" : "KFC",
"image_url" : "appicon.png",
"address" : "7675 Sawmil road, Texas",
"tags" : ["indian", "asian"]
}]
};
// Create a TableView.
var listTable = Ti.UI.createTableView({
backgroundColor : "#fff"
});
// Populate the TableView data.
var data = [];
var response = jsonData;
Ti.API.info("@@## : jsonData = " + jsonData.toString());
for (var i = 0; i < response.restaurants.length; i++) {
var restaurant = response.restaurants[i];
var row = Titanium.UI.createTableViewRow();
row.resId = restaurant.id;
var thumpImage = Titanium.UI.createLabel({
width : '80dp',
top : '20dp',
left : '10dp',
height : '80dp',
backgroundImage : restaurant.image_url
});
row.add(thumpImage);
var detailView = Ti.UI.createView({
layout : "vertical",
height : Ti.UI.SIZE,
left : '100dp'
});
row.add(detailView);
var titleLabel = Titanium.UI.createLabel({
text : restaurant.title,
color : '#000',
height : Ti.UI.SIZE,
font : {
fontSize : '16dp',
fontWeight : 'bold',
fontFamily : 'Helvetica Neue'
},
textAlign : 'left',
left : 0,
top : '5dp'
});
detailView.add(titleLabel);
var addressLabel = Titanium.UI.createLabel({
text : restaurant.address,
color : '#000',
height : Ti.UI.SIZE,
font : {
fontSize : '14dp',
fontWeight : 'normal',
fontFamily : 'Helvetica Neue'
},
textAlign : 'left',
left : 0,
top : '7dp'
});
detailView.add(addressLabel);
var tagLabel = Titanium.UI.createLabel({
text : restaurant.tags.toString(),
color : '#000',
height : Ti.UI.SIZE,
font : {
fontSize : 14,
fontWeight : 'normal',
fontFamily : 'Helvetica Neue'
},
textAlign : 'left',
left : 0,
top : '7dp'
});
detailView.add(tagLabel);
data.push(row);
}
listTable.setData(data);
// Listen for click events.
listTable.addEventListener('click', function(e) {
alert('ID: \'' + e.row.resId);
});
// Add to the parent view.
win.add(listTable);
win.open();
@pundu55
Copy link

pundu55 commented Oct 18, 2013

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment