2014-10-02 129 views
-3

我的問題很可怕,我很抱歉。如何通過按下Titce Appcelerator中的另一個按鈕來創建按鈕?

所以我想要做的是進入createNewCourseScreen,輸入名稱並設置顏色並按下創建按鈕,創建的按鈕將在coursesScreen中的其他按鈕下彈出。

我是鈦金屬的meganoob,需要你的幫助!

屏幕 coursesScreen:http://s30.postimg.org/do1jrlrrl/courses.png newCourseScreen:http://s29.postimg.org/7c15cxnon/newcourse.png

+0

你嘗試過什麼到目前爲止,你可以分享?任何代碼? – 2014-10-02 23:58:49

回答

1

你可能會在這個思維過程複雜化。也許你正在使用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); 
    } 
+0

你是我的英雄<3 – 2014-10-04 03:16:29

相關問題