2013-02-06 44 views
0

嗨我想建立一个简单的移动应用程序使用钛工作室和面临的问题,从Android模拟器中的表视图列表项打开新窗口。这是我在我的js文件中使用的代码。新窗口是不是在Android模拟器使用钛打开

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

是regItemList单击事件工作?你有没有在日志中看到任何错误或警告? –

+0

是的,它正在工作,例如,如果我把警报();它显示了警报窗口。 – Raghav

回答

0

我做了一些修改的代码,它工作正常现在

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

你犯了一个简单的错误。 您没有将选项卡添加到tabGroup。 只是将下面的行添加到您的代码:

tabGroup.addTab(tab); 

就是这样。希望它会有所帮助。

相关问题