0

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);
2
  • Is regItemList click event working?? And do you see any error or warning in log?? Feb 6, 2013 at 13:53
  • Yes, It is working, for example if I put an alert(); it shows the alert window.
    – Raghav
    Feb 7, 2013 at 8:56

2 Answers 2

0

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);
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.