Titanium Community Questions & Answer Archive

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

Dynamic Window creation.. help ???

my app requires dynamic window creation. The app contains a tbview that drills down to open subsequent tbviews in different windows.

the problem i face is that i cannot assume at the start on how many sub windows the app requires as the app will be consuming different xml of varying depths to feed the table view.(to be simple , elements of subsequent depth in xml will be populated in a separate tableview in a separate window).

can somebody help me on this issue please…i was thinking if there might be a way to create windows dynamically i will be able to add it to a navgroup that will take care of the back transitions under the hood.

every node given below requires a table view embeded in a separate window.

eg1. scenario1 - datasource:1.json

 1)...
   -1.1)...
     1.2)...
        -1.2.1)...
          1.2.2)...
               -1.2.2.1)...
               -1.2.2.2)...
               -1.2.2.3)...
          1.2.3)...
     1.3)...
     1.4)...

eg1. scenario2 - datasource:2.json

 1)...
   -1.1)...
     1.2)...
        -1.2.1)...
          1.2.2)...                   
     1.3)...
     1.4)...

or proposal of any other design practice will be appreciated…

— asked October 28th 2010 by Satta Ravi
  • design
  • dynamic
  • iphone
  • practises
  • window
2 Comments
  • what is the content of the window? Is there a pattern?

    — commented October 28th 2010 by Aaron Saunders
  • Content of every window is a table view. and the content of every table view is got from an Xml

    — commented October 29th 2010 by Satta Ravi

2 Answers

  • Hi there,

    I think the solution lies in converting the hierarchical data into a flat list. i.e. for each item you'd need to define a "parent element id" when parsing.

    So that:

    1. Your initial tableview would be all where parent is null,

    2. On row select, take the "id" and build a new array of items with that as the "parent id" and repeat ad infinitum.

    You probably need to open a new window with each drilldown in order to get the 'back button' to do it's thing for free. Coding that manually would be v. tricky.

    cheers,
    Chris.

    — answered October 28th 2010 by Chris Reed
    permalink
    0 Comments
  • Hi chris,

    Thanks for your reply.,i already have all the elements in the xml in a parent-child relationship(i maintain id's to define the parents).

    And the Thing is that i was successful with my app by dynamically adding views containing tbviews.

    And just as you guessed drilling back up to the first tbview is chocking me now..that was why i wanted to use navgroups (raised this question on the forum )as it could take care of back transitions and more important does a cool drill down animation between windows by default and am now stuck up creating new windows dynamically…

    can you get me pointers how to on create windows dynamically…

    here is my code creating views dynamically.

    var data,
        prev=null;
    
    var win=Ti.UI.createWindow({title:test});
    win.addEventListener('open',function(e){
      appInit();
    });
    win.open();
    
    function parser(url){
      //parse the file and store the object globally.
      //fetch elements and fill it in var data   
      createVu();
    }
    
    function appInit(){ 
      //app initailise xml
      var url="x.xml";
      parser(url);
    }
    
    function clicked(id){
     //drill down to the next level of elemnts with the parent ID of id
     //fetch all elements and fill it in var data
     createVu();
    }
    
    function createVu(){
     if(prev!=null){
      win.remove(prev);
     }
     var Vu=Ti.UI.createView();
     var tbVu=Ti.UI.createTableView({data:data});
     tbVu.addEventListener('click',function(e){
      clicked(e.rowData.ID);
     });
     Vu.add(tbVu); 
     prev=Vu;
     win.add(Vu);
    }
    
    — answered October 29th 2010 by Satta Ravi
    permalink
    0 Comments
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.