我是鈦工作室的新手。我試圖做到這一點,當用戶點擊window1中的任何按鈕,它會進入第二個窗口。我的意思是我無法連接到button1和button2以通過第二個窗口。我不能去加油器的第二個窗口
這是我的示例代碼。任何人都可以幫助我嗎?
Titanium.UI.setBackgroundColor('#000');
var win1 = Ti.UI.createWindow({
layout : 'vertical',
title : 'Welcome to BMI'
});
var button1 = Ti.UI.createButton(
{
title:'Standart',
top : 300,
height: 20,
width: 100
});
button1.addEventListener('click', function(e)
{
win1.close();
win2.open();
});
var button2 = Ti.UI.createButton(
{
title:'Metric',
top : 350,
height: 20,
width: 100
});
button2.addEventListener('click', function(e)
{
win1.close();
win2.open();
});
win1.add(button1);
win1.add(button2);
win1.open();
var win2 = Ti.UI.createWindow({
backgroundColor: 'white',
layout: 'vertical',
title: 'BMI'
});
var label1 = Ti.UI.createLabel({
color: '#900',
font: { fontSize:48 },
shadowColor: '#aaa',
shadowOffset: {x:5, y:5},
text: 'Body Mass Index',
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
top: 30,
width: Ti.UI.SIZE, height: Ti.UI.SIZE
});
var label2 = Ti.UI.createLabel({
color:'blue',
text: 'Welcome to BMI',
textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
top: 30,
width: 300, height: 200
});
win2.add(label1);
win2.add(label2);
嗨,我已經在Android上測試了您的代碼與SDK 3.1.3GA,它適用於我。我看到win1(黑色背景)上的按鈕1和按鈕2,然後我按下一個按鈕,它打開win2(白色背景)。怎麼了?你期望另一種行爲? – kabomi
是的,我處理了這個問題。這裏是問題, win1.add(button1); win1.add(button2); win1.open(); 我刪除了win1.open()它開始工作。當我將win1.open()放在那裏時,我認爲編譯器會看到代碼並開始運行第一個窗口。我不需要這樣。 – arsnlupn