Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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 

    // 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?

— asked May 3rd 2010 by Michael Gajda
  • dynamical
  • iphone
  • mobile
  • variables
  • xhr

1 Answer

  • You can dynamically create variables and views like this:

    eval(myNewVariable+" = Titanium.UI.createImageView({"+
                "image: 'myImage.png')"+

    Hope this helps.

    — answered June 10th 2010 by Richard James
    1 Comment
    • Thank you man, your answer helped me a lot, I searched for several hours for that in the last two days until I found your answer.

      — commented June 24th 2012 by Goethe ...
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.