Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Android Move/Edit Rows?

I'm pretty sure Titanium doesn't support a method to easily edit or move table view rows for Android. I believe this is because Android doesn't have a similar native functionality. I'm not an Android user, so I'm not familiar with how this functionality is often accomplished in apps.

Can recommend a way to implement similar functionality in my own code for Android. What methods have you tried? What have you seen in other apps?

— asked September 30th 2010 by Mike Robinson
  • algorithm
  • android
  • edit
  • method
  • move
  • row
  • tableview
3 Comments
  • I would also like to know.

    — commented October 4th 2010 by Ben Hornedo
  • Please share the result if u got?

    — commented August 27th 2013 by Jithin George
  • Hi.Mike
    Have you found a solution?

    — commented February 21st 2015 by Wang Dan

1 Answer

  • Slide

    I was able to get rows to be able to be moved by dragging them (just like on iPhone) on Ti Mobile 1.6.1 and Android 1.6, by attaching a table to a scroll view, tracking the offset of the touchmove event on the scrollview, and then firing a move row function according to where the row moved to.

    The problem comes when moving the row fast, because the touchmove event fires randomly, so you may be dragging row 1 below row 5, but the offsets may tell you you are moving row 2 below row 4. Thus, I had to find another solution.

    Drag & Drop

    Using the same setup, a table view attached to a scroll view, you can drag a row and then fire the move function on touchend. This will work consistently, but because the UI doesn't change until you've dropped the row, the user never really knows where they are dropping it. So from a UI standpoint this is out of the question.

    Buttons

    The only way to move rows in an appropriate manner, is to make up and down arrows on each row, attach a click event on each row and then fire the move row function. The trick to knowing whether to move it up or down is to add a custom property, call it 'direction', to each image you attach to the row, and then do something like:

    row.addEventListener('click',function(e){
        if (typeof(e.source.direction)!='undefined') {
            moveRow(e.index, e.source.direction);
        }
    });
    

    So, note that you are feeding the index of the row to the function, and then the direction 'up' or 'down'. You'll have to write the code to take that index, insertRowBefore on up and insertRowAfter on down and then delete the original index.

    — answered April 13th 2011 by Joe iEntry
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.