【问题标题】:New window is not opening in Android Emulator using Titanium使用 Titanium 的 Android 模拟器未打开新窗口
【发布时间】:2013-02-06 13:40:07
【问题描述】:

您好,我正在尝试使用 Titanium Studio 构建一个简单的移动应用程序并面临问题,以便从 Android 模拟器中的表格视图列表项打开新窗口。这是我在 js 文件中使用的代码。

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

【问题讨论】:

  • regItemList 点击事件是否有效?您是否在日志中看到任何错误或警告?
  • 是的,它正在工作,例如,如果我放了一个 alert();它显示警报窗口。

标签: android mobile android-emulator titanium titanium-mobile


【解决方案1】:

我对代码做了一些更改,现在可以正常工作了

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

【讨论】:

    【解决方案2】:

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

    tabGroup.addTab(tab);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-29
      • 2016-09-17
      • 1970-01-01
      相关资源
      最近更新 更多