你可能会在这个思维过程复杂化。也许你正在使用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