Nadhas
Nadhas

Reputation: 5807

How to implement long press/swipe and delete on table rows - android titanium?

I having a tableView having some rows with labels. I want to delete row on long press/swipe on a particular row. I have added long press event for tableView but its callback method re the parameter as label which is in the tableViewRow.

how to get the selected index of the row???

table.addEventListener('longpress', function(e) {
            alert(e.source); //showing LabelProxy@2389hf

        });

Upvotes: 2

Views: 3427

Answers (1)

Nitin
Nitin

Reputation: 231

Try below code for delete row on longClick.

var win = Ti.UI.currentWindow;
var data=[];
for (var x = 0; x < 4; x++) {
//var view = Ti.UI.createView();
var label = Ti.UI.createLabel({
    text : 'Row Label ' + x,
    height : 'auto',
    width : 'auto',
    color : '#336699',
    left : 10
});
var row = Ti.UI.createTableViewRow({
    height : 50
});
row.add(label);
    data.push(row);
}

// create table view
var tableview = Titanium.UI.createTableView({
    data : data
});
tableview.addEventListener('longclick', function(e) {
    tableview.deleteRow(e.index);
});
win.add(tableview);

Upvotes: 1

Related Questions