Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I do re-order table view collection view values in Titanium Studio Android?

Tags:

titanium

I want to show some details like names with address of the clients, when I have to re-order the list of the view like the user can drag and drop 3rd row into 5th place and 6th row into 10th place like this I need,in titanium studio for android.

will any one help me. I am at basic level in titanium.

like image 837
Venu Gopal Reddy Avatar asked Jan 20 '26 06:01

Venu Gopal Reddy


1 Answers

Drag and drop support is for iOS only (at least through the Titanium SDK). Further, I don't believe I've seen drag and drop in an Android app for row re-ordering. But I have seen up and down arrows to let you re-order. Below is sample code using a TableView. If you use ListView, the code can be even cleaner (you can use replaceItemsAt to swap the items without updating the whole list).

var win = Ti.UI.createWindow({
    backgroundColor: '#fff',
    fullscreen: true
});

var data = [];

for(var i = 1; i <= 10; i++) {
    var row = Ti.UI.createTableViewRow();
    row.add(Ti.UI.createLabel({
        text: 'Row ' + i, textAlign: 'left',
        width: Ti.UI.FILL, color: '#000'
    }));
    row.add(Ti.UI.createButton({
        title: 'Up', action: 'moveUp',
        width: 50, right: 70
    }));
    row.add(Ti.UI.createButton({
        title: 'Down', action: 'moveDown',
        width: 50, right: 10
    }));
    data.push(row);
}

var table = Ti.UI.createTableView({
    data: data
});
table.addEventListener('click', function(evt) {
    var action = evt.source.action,
        index = evt.index,
        isFirstRow = index === 0,
        isLastRow = index + 1 === data.length;
    if(action === 'moveUp' && !isFirstRow) {
        swapRows(index, index - 1);
    }
    else if(action === 'moveDown' && !isLastRow) {
        swapRows(index, index + 1);
    }
});
win.add(table);

win.open();

function swapRows(indexOne, indexTwo) {
    var temp = data[indexOne];
    data[indexOne] = data[indexTwo];
    data[indexTwo] = temp;
    table.data = data;
}
like image 151
Dawson Toth Avatar answered Jan 23 '26 21:01

Dawson Toth