Titanium Community Questions & Answer Archive

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

how to open window on android and iphone?

I have created a tabgroup on app.js as


var tabGroup = Titanium.UI.createTabGroup();

   var win1 = Titanium.UI.createWindow({
        url:'login.js',
        backgroundColor:'#FFFFFF'
          });


   var tab1 = Titanium.UI.createTab({  
        title:'Login',
        window:win1
          });    

   var win2 = Titanium.UI.createWindow({
            title:'Search',
            backgroundColor:'#fff',
            barColor:'#000000'
        });



   var tab2 = Titanium.UI.createTab({  
            title:'Search',
            window:win2
        });


   tabGroup.addTab(tab1);  
   tabGroup.addTab(tab2);  


    // open tab group
   tabGroup.open();

Then in login.js


var win=Titanium.UI.currentWindow;

var button = Ti.UI.createButton({
    title:'login'
});

var indexWin = Ti.UI.createWindow({
    url:'index.js',
    title:'index'
});

button.addEventListener('click',function(e){

   indexWin.open(); //does not work

});

win.add(button);

Then in index.js

var win=Titanium.UI.currentWindow;

var text = Ti.UI.createTextField({
    top:60,
    left:10,
    width:300,
    height:40
});

win.add(text);

I do not know why the index window do not show ?
this code run on iphone, it is ok, but it run on android, it is not ok.

— asked November 19th 2010 by becca zhang
  • android
  • iphone
  • mobile
  • open
  • window
0 Comments

2 Answers

  • Hi Becca

    Your code is really almost there, and only needs a couple of slight adjustments to be much improved! :)

    Firstly, in login.js, you probably will want to set navBarHidden:false on indexWin, to make the window "modal" (heavyweight view) meaning that when the user clicks the android back button, it will return to app.js, rather than exiting the app.

    Secondly, be careful in your login.js script; you are creating indexWin outside the eventListener, and opening it inside. This means that when the window is opened by the event, and then closed using the android back button, the window still exists. Consequently, anything you added while the window was open also still exists and is still added. Every time the event occurs thereafter, more and more of exactly the same objects will be added to indexWin window. If your layout is absolutely positioned, then you probably won't even notice, because they will be stacked precisely on top of each other. I hope you see what I mean - it's not easy to explain.

    So, that's it - here's your working code (excuse the colours, which I use to make it clearer what is going on):

    app.js

    var tabGroup = Titanium.UI.createTabGroup();
    
    var win1 = Titanium.UI.createWindow({
        backgroundColor:'red',
        url:'login.js'
    });
    
    
    var tab1 = Titanium.UI.createTab({
        title:'Login',
        window:win1
    });
    
    var win2 = Titanium.UI.createWindow({
        backgroundColor:'green',
        title:'Search',
        barColor:'#000000'
    });
    
    var tab2 = Titanium.UI.createTab({
        title:'Search',
        window:win2
    });
    
    
    tabGroup.addTab(tab1);
    tabGroup.addTab(tab2);
    
    
    tabGroup.open();
    

    login.js

    var win=Titanium.UI.currentWindow;
    
    var button = Ti.UI.createButton({
        title:'login'
    });
    
    button.addEventListener('click',function(e){
        var indexWin = Ti.UI.createWindow({
            backgroundColor:'blue',
            navBarHidden:false,
            url:'index.js',
            title:'index'
        });
        indexWin.open();
    });
    
    win.add(button);
    

    index.js

    var win=Titanium.UI.currentWindow;
    
    var text = Ti.UI.createTextField({
        top:60,
        left:10,
        width:300,
        height:40
    });
    
    win.add(text);
    
    — answered November 19th 2010 by Paul Dowsett
    permalink
    1 Comment
    • hi Hal H

      then index.js want to showed tabgroup

      index.js

      var win=Titanium.UI.currentWindow;
      
      var tabMenu = Titanium.UI.createTabGroup();
      
      var win1 = Titanium.UI.createWindow({
          backgroundColor:'red',
          title: 'home1'
      });
      
      
      var tab1 = Titanium.UI.createTab({
          title:'Login',
          window:win1
      });
      
      var win2 = Titanium.UI.createWindow({
          backgroundColor:'green',
          title:'home2'
      });
      
      var tab2 = Titanium.UI.createTab({
          title:'home2',
          window:win2
      });
      
      
      tabMenu.addTab(tab1);
      tabMenu.addTab(tab2);
      
      
      tabMenu.open();
      curWin.add(tabMenu);
      

      This code run on iphone, it is ok, but it run on android, it is not ok. show "Sorry! The pplication test(process com) has stopped unexectedly. Please try again."

      — commented November 22nd 2010 by becca zhang
  • Becca

    Is this issue still troubling you? To get meaningful exception messages for android, you need to run the following at the command line:

    adb -e logcat
    

    Note that my code was tested on android, and it worked. If it doesn't for you, install the latest 1.4.X continuous build from here.

    If it's still a problem, pastebin the output of logcat and I will advise you further.

    — answered December 1st 2010 by Paul Dowsett
    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.