views:

64

answers:

1

Let's say I have a ListView of items:

  • Cat
  • Dog
  • Mouse

And these are bound to the ListView via an adapter to a database.

What I want to be able to do is to be able to re-order the list view,. For example I want to somehow drag "Mouse" up to the top of the list above "Cat". Once I have an order set, I then want to "save" the list and its order back to the database.

Is there any way to do this? Has someone made such a custom ListView that I could use? The only alternative I can think of is to long press on a list view item and have a "Move up by one", "Move to top", etc. context menu that moves items around in the list.

+1  A: 

Android's music application does that with the playlist. Check it's source code here.

Macarse
I have that stuff packaged up as a reusable component: http://github.com/commonsguy/cwac-touchlist -- note that an update should get pushed out in the next 24-48 hours.
CommonsWare
@CommonsWare: what are you going to add?
Macarse
@Macarse: the existing project does not so much "add" as "tease the code out of the tie-in to the Music app so it's reusable". The pending updates are simply reflecting a reworking of the parcel system to use Android library projects, plus a bit of cleanup on how some of the custom attributes are named.
CommonsWare
@CommonsWare Nice, I'll look at your component soon. I'm in no rush for this particular piece of the puzzle, so I can wait for your update.
Bryan Denny