Search code examples
javascripttitanium

JavaScript: Button in a table view


i have a problem with button inside TableViewRow - with info_button. This button is created on each row of TableViewRow in for cyklus. When i click it, it works fine, open alert dialog as i want to, but then it opens also the code which belongs to tableView Row. (I cut unimportant piece of code, so there are maybe some mistakes, but it works fine)

var url = "http://hotel.010.sk/skyfit/mysql.php";
var win = Titanium.UI.currentWindow;
var table = Ti.UI.createTableView();
var tableData = [];
var json, harmonogram, vypis, i, row, nameLabel, nickLabel, cvicenie, harmon, backLabel;

var xhr = Ti.Network.createHTTPClient({
onload: function() {
// Ti.API.debug(this.responseText);

json = JSON.parse(this.responseText);


for (i = 0; i < json.harmonogram.length; i++) {
    vypis = json.harmonogram[i];


    row = Ti.UI.createTableViewRow({
        height:80,
        hasChild:true, 
        url:'tab1.js'

    });

var info_button =  Titanium.UI.createButton({
    style:Titanium.UI.iPhone.SystemButton.DISCLOSURE,
    right: '5dp',
    top: 5,
    //buttonid : i 
    id: "image"
});

Here is my info_button, I need to open only this piece of code

info_button.addEventListener('click', function(e) {

          var about = Titanium.UI.createAlertDialog({
            title: 'O cvičení',
            message: vypis.nazov,
            buttonNames: ['OK']
    });
    about.show();

});

//here is CODE for some LABELS, its not important for my problem


row.add(nameLabel);
row.add(nickLabel);
row.add(info_button);
tableData.push(row);


   };


table.setData(tableData);
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT:   " + this.responseText);
Ti.API.debug("ERROR:  " + e.error);
alert('There was an error retrieving the remote data. Try again.');
},
timeout:5000
});


xhr.open("GET", url);
xhr.send();

And it opens also this Listener and I need to open only info_button if user click on it.

**table.addEventListener**('click', function(e) {


//here is code for Listener

}); 

win.add(table);

win.open();

Thanks a lot!


Solution

  • Set bubbleParent property of button to false.

    for example :-

    Var info_button =  Titanium.UI.createButton({
            bubbleParent: false
    });