Tutorial :How can I allow a user to re-sort items in a list?


I have an Android app where users can add items to a list, and I'd like them to be able to re-order the items in the list however they want (as opposed to just offering them different sort orders). It's easy enough to add a position setting for the items (they come from the DB) but what kind of UI elements are available for the user to indicate the desired ordering?

Is there a pattern anyone has seen implemented for this? I have not seen anything on Android that does anything like this, except the home screen which is similar but looks a little bit beyond my expertise at this point. The best I can think of is to use a long click and context menu to "move up" or "move down".


I just found this: Android List View Drag and Drop sort after some searching and browsing. I thought it makes sense to link it here, because this is the first question that comes up when searching for reorderable lists in android.


Well, there's the right answer, and my answer. :-)

The right answer is drag-and-drop. There's some code for that floating around the Android source for the Music app, but it's outside my skill level with touch events right now.

In the one case I wanted this feature, I created a list using up/down buttons to let the user resequence. Ugly, but it works.

Using a context menu, as you indicate, can certainly be made to work, but if you can spare the on-screen real estate, putting the buttons on will be easier. You might even consider toggling the button visibility on/off via an option menu, if having them on-screen the whole time will be unpleasant.

And, someday, I hope to make a drag-and-drop ReorderableListView as a reusable component...but I wouldn't hold your breath. Maybe somebody else has one that I haven't run across yet.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »