Dynamicly create Windows
Hi there,
i got a big problem to create dynamicly my detail-windows.
My structure looks like this:
function GUI1(){
var dataKey = 'json';
var itemList = usersession.data[dataKey];
for (var i = 0; i < 5; i++) {
var eventId = itemList[i].game['@id'];
Ti.API.info('eventId ' + i + ' ' + eventId);
var eventObject = new Xhr();
eventObject.getResponse('http://somewebsite.com/rest/game/' + eventId, 'json2', GUI2);
}
}
In my Funtion GUI2 i create a Table an add it to my view
var toplistTable = Titanium.UI.createTableView({
data: tabledata,
top: 28,
height: 350,
rowHeight: 70,
backgroundImage: '../images/tableBG.png',
zIndex: 10
});
//add table
Ti.UI.currentWindow.add(toplistTable);
// event listener for toplistTable --begin
toplistTable.addEventListener('click', function(e){
if (e.rowData.test) {
var win = null;
if (Ti.Platform.name == "android") {
win = Titanium.UI.createWindow({
url: e.rowData.test,
title: e.rowData.title
});
}
else {
win = Titanium.UI.createWindow({
url: e.rowData.test,
title: e.rowData.title,
backgroundColor: '#fff',
barColor: '#111',
gameIdent: GameId
});
}
Titanium.UI.currentTab.open(win, {
animated: true
});
}
});
//event listener -- end
So my problem is that after loading my app, every detail-page is filled with the data from my GameId of the last entry of my table.
So i want to create with each time i get througt the loop a dynamical varible name for the event listener window.
Is that possible, or am i on a totally wrong way?
1 Answer
-
You can dynamically create variables and views like this:
eval(myNewVariable+" = Titanium.UI.createImageView({"+ "height:50,"+ "width:50,"+ "top:10,"+ "left:10,"+ "backgroundColor:'#999',"+ "image: 'myImage.png')"+ "});");
Hope this helps.
Jamesy