add an event to a single row

You must Login before you can answer or comment on any questions.

hello guys, how can I add an event to a single row of a table?

— asked 9 months ago by Giuseppe Parasiliti
1 Comment
  • giuseppe , imposta un id ad ogni riga della tabella , e poi controlli quale hai premuto , per esempio se hai una tabella con 10 righe :

    for(i=0;i<10; i++)
        {
            var cancelBtn; <-- questo sarò il pulsantino affianco alla row
            var row;     
            var myimage;
     
                cancelBtn = Ti.UI.createButton({
                style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN,
                buttonid:i
                });
     
               cancelBtn.addEventListener('click',function(e){
                    if(e.source.buttonid==0)
                    {
                        // fai qualcosa
                    }
                       if(e.source.buttonid==1)
                    {
                        // fai qualcos'altro
                    }
               }
    }

    — commented 9 months ago by nicolò monili

1 Answer

Just as with other parts of the UI, TableViewRows have to ability to listen for events. So during your table creation, you can add an event listener just to the row that you want.

var row = Ti.UI.createTableViewRow();
row.addEventListener('click', function(e) {
});

— answered 9 months ago by Anthony Decena
answer permalink
1 Comment
  • On a side note, it may just be easier to put the click event on the entire table and just check the index of the row clicked. If the index matches the row that you wanted to attach the event to, then fire off the action that you wanted to attach to that row.

    — commented 9 months ago by Anthony Decena

Your Answer

Think you can help? Login to answer this question!