Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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".

like image 816
sosiouxme Avatar asked Feb 18 '10 16:02

sosiouxme


1 Answers

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.

like image 69
CommonsWare Avatar answered Oct 04 '22 22:10

CommonsWare