简体   繁体   中英

New window is not opening in Android Emulator using Titanium

Hi I am trying to build an simple mobile app using Titanium Studio and Facing problem to open new window from table view list item in Android Emulator. Here is the code which is I am using in my js files.

app.js

    var tabGroup = Titanium.UI.createTabGroup();

var win = Titanium.UI.createWindow({  
    backgroundColor: "#FFF"
});
var tab = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'REGISTRY',
    window:win
});

var regItems = [ 
    {title: "List Item One", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true},
    {title: "List Item Two", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true},
    {title: "List Item Three", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true}
]

var regItemList = Titanium.UI.createTableView({
    data: regItems
});

regItemList.addEventListener('click', function(e){
     var win2 = Titanium.UI.createWindow({ 
        url: "newWin.js",
        title: e.rowData.title,
        backgroundColor: "#273691"
     }); 

      win2.open();
//    tab.open(win2, {animated: true}); This is also not working

});

win.add(regItemList);

// open tab group
tabGroup.open();

newWin.js

var newWinCreate = Titanium.UI.currentWindow;

var labelName = Titanium.UI.createLabel({
    title: "First Name",
    font: {fontSize: 18},
    top: 10,
    left: 20,
    color: "#fff",
    textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER
});

newWinCreate .add(labelName);

I made some changes to the code and it is working fine now

app.js

var tabGroup = Titanium.UI.createTabGroup();
a
var win = Titanium.UI.createWindow({  
    backgroundColor: "#FFF"
});
var tab = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'REGISTRY',
    window:win
});

var regItems = [ 
    {title: "List Item One", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true},
    {title: "List Item Two", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true},
    {title: "List Item Three", font:{fontSize: 25, fontWeight: 'bold'}, color: "#45165C", leftImage:"images/regImg.gif", className: "tableRow", hasDetail: true}
]

var regItemList = Titanium.UI.createTableView({
    data: regItems
});

regItemList.addEventListener('click', function(e){
     var win2 = Titanium.UI.createWindow({ 
    url: "newWin.js",
    title: e.rowData.title,
    backgroundColor: "#273691"
 }); 

  win2.open();
//    tab.open(win2, {animated: true}); This is also not working

});

win.add(regItemList);

tabGroup.addTab(tab);

// open tab group
tabGroup.open();

newWin.js

var newWinCreate = Titanium.UI.currentWindow;

var labelName = Titanium.UI.createLabel({
    text: "First Name",
    font: {fontSize: 18},
    top: 10,
    left: 20,
    color: "#fff",
    textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER
});

newWinCreate.add(labelName);

You have made a simple mistake. You didn't added the tab to tabGroup. Just add the following line to your code:

tabGroup.addTab(tab);

That's it. Hope it will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM