你可能會在這個思維過程複雜化。也許你正在使用Alloy,在看到如何實現這一點時不那麼直接。在傳統的Titanium中,你已經有了代碼來展示如何創建按鈕和事件監聽器盯着你。
一般步驟: 1 - 獲取標題和顏色的輸入。 2 - 調用onClick或addEventListener('click',...處理程序創建按鈕 3 - 在處理此事件的函數中,使用Ti.UI.createButton創建一個按鈕 4 - 創建一個事件偵聽器。它 5 - 添加按鈕,你想讓它顯示在屏幕
經典:
// Using the same logic that created the other buttons
function createButtonPress(){
// Store information about new button created somewhere so that it
// shows up the next time the application is run.
// Create the button.
var newButton = Ti.UI.createButton({
title: nameFromTextField.value
color: colorFromTextField.value
});
newButton.addEventListener('click', function(){
// Thing you want the new button to do when pressed.
});
viewHoldingButtons.add(newButton);
}
合金:
function createButtonPress(){
// Store information about new button created somewhere so that it
// shows up the next time the application is run.
// Create the button.
var newButton = Ti.UI.createButton({
title: nameFromTextField.value
color: colorFromTextField.value
});
newButton.addEventListener('click', function(){
// Thing you want the new button to do when pressed.
});
$.viewHoldingButtons.add(newButton);
}
你嘗試過什麼到目前爲止,你可以分享?任何代碼? – 2014-10-02 23:58:49