3

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.

Venu Gopal Reddy
  • 301
  • 1
  • 3
  • 13
  • You need to provide more details and some initial code showing what you were trying to achieve and at exactly which point you have a problem. – daniula Jan 06 '14 at 20:34

1 Answers1

3

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;
}
Dawson Toth
  • 5,580
  • 2
  • 22
  • 37
  • thanks for this code its working fine, can I do that reordering without buttons for listview or Tableview? – Venu Gopal Reddy Jan 07 '14 at 06:44
  • Maybe if you make a custom module. I know Titanium doesn't expose (as of January 2014) the APIs necessary. You could look at this SO Q&A to find out more: http://stackoverflow.com/questions/2909311/android-list-view-drag-and-drop-sort – Dawson Toth Jan 07 '14 at 18:38
  • Hi Dawason, I want to reorder only table view rows, like the following like http://tinypic.com/view.php?pic=104m0kk&s=5#.Us_jgNIW3a8. any suggestions. do we can use move property? – Venu Gopal Reddy Jan 10 '14 at 12:12
  • The `moveable` property is iOS only. My suggestion for Android is the code sample in the answer. http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.TableView-property-moveable – Dawson Toth Jan 10 '14 at 16:32
  • can somebody translate that code into java PLEASE !!! THANKS IN ADVANCE – jhayjhay Feb 01 '19 at 06:11
  • @jhayjhay This is a #Titanium specific Q&A, but there are plenty of Android/JAVA specific Q&As for you to reference -- see https://stackoverflow.com/questions/2909311/android-list-view-drag-and-drop-sort and https://stackoverflow.com/questions/3141144/reordering-of-listview-items-by-drag-and-drop-using-android Translating the above JavaScript to JAVA would be useless to you, because you don't have the abstraction that Titanium provides. – Dawson Toth Feb 01 '19 at 18:09