1

私は貿易によるプログラマーではありませんが、いじくり回す人です(noob)

配列に含まれるタイトルからメニューを作成したい。配列をループし、ループの各ステップの値をボタン/タブのタイトルとして使用することで、これを正常に実行しました。

ユニークなページへのリンクを含む各ボタンにイベントリスナーを追加したいと思います。ボタンのラベルをチェックし、それが値Aの場合、対応するリンクなどを取得し、それをcurrentLinkに割り当てることでこれを行うつもりでした。このリンクは、リンクを通過するたびにLink[t]によって参照されます。ループ。

私はそれがほぼ機能していると思いますが、リンクビットを動的に追加することに失敗しました。

どんな助けでも大歓迎です。

これが私のコードです:

//function to check the label name and assign the relevant filename to be passed on
    function winLink(currentTab){
     if (currentTab == 'Audio'){
      currentLink = 'audioPlayer.js';
      pageWin.url = currentLink;

     } else{
      if (currentTab == 'Images'){
      currentLink = 'images.js';
      }
     } 
    }

//function to change button colours according to active button
function button_colour(e){
 if (clickedButton == ''){
  clickedButton = e.source; 
  clickedButton.backgroundImage = tabBckImgSel;

 } else {
  clickedButton.backgroundImage = tabBckImg;
  clickedButton = e.source; 
  clickedButton.backgroundImage = tabBckImgSel;
  }
}


    //Array that contains button names
    var tabsArray =['Audio','Images','Video','Info','Materials','Further Reading','Map'];

//loop through array and create a holder, label and eventlistener to attach
for (var t=0;t<tabsArray.length;t++) {
 //create view to act as button/tab area
 viewButton[t] = Titanium.UI.createView({
  borderWidth:1,
  borderColor: tabBrdrColour,
  width:tabWidth,
  height:tabHeight,
  left:leftTab + padding
 });

 //add the tab to the main menu view/area
 menu.add(viewButton[t]);

 //increment the left position for the next button to be placed to the right of the previous button
 leftTab = viewButton[t].left + tabWidth;

 Buttonlabel[t] = Titanium.UI.createLabel({
  text: tabsArray[t],
  font:{fontSize:13},
  color:'#fff',
  width:labelWidth,
  textAlign:'center',
  height:'auto'
 });

 viewButton[t].add(Buttonlabel[t]);

    //pre declared variable  to hold the title of the current label
 currentTab = tabsArray[t];
//call to function to check label and set the relevant file to load
 winLink(currentTab);

 viewButton[t].addEventListener('singletap', function(e)
  {

  button_colour(e);
  win.add(pageWin);
var theLink[t] = currentLink;
  // alert (' Current link' + currentLink);
 });

}
4

1 に答える 1

0

ハッシュテーブルはあなたが探しているものでしょうか? これらのリンクを動的に作成して使用できるようになります。

http://download.oracle.com/javase/1.4.2/docs/api/java/util/HashSet.html

また、私はこれを変更します...

  //function to check the label name and assign the relevant filename to be passed on
function winLink(currentTab){
 if (currentTab == 'Audio'){
  currentLink = 'audioPlayer.js';
  pageWin.url = currentLink;
  } else{
  if (currentTab == 'Images'){
  currentLink = 'images.js';
  }
 } 
}

に...

       //function to check the label name and assign the relevant filename to be passed on
function winLink(currentTab){
 if (currentTab == 'Audio'){
  currentLink = 'audioPlayer.js';
  pageWin.url = currentLink;
  } else if(currentTab == 'Images'){
  currentLink = 'images.js';
  }
 } 

それは私を悩ませていました:)

于 2010-12-03T13:35:40.113 に答える