24

How can I create a list where I can rearrange list items with dragging list rows to another row and so on (to change to order)?

Just like on the HTC Hero in the clocks app where you can rearrange the order of clocks?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
wouter88
  • 1,294
  • 4
  • 15
  • 19

5 Answers5

34

Even though this question is already answered. I struggled using the music app as an example, so I created a simple Drag and Drop List project to help others that can be found here

ericharlow
  • 2,045
  • 3
  • 21
  • 26
  • 1
    This a very clear and straightforward project that makes it easy to extend. I easily converted it to a ListFragment and plan to change it so that it works with cursors. Thanks for sharing this project! – Luis Nov 05 '12 at 13:50
20

Pay special attention to this one

com.android.music.TouchInterceptor

Bo.
  • 580
  • 5
  • 17
11

You can also try my recent implementation here:

It gives smooth scrolling while dragging and supports list items with arbitrary heights. Lots of jumpy behavior has also been removed as compared to the TouchInterceptor.

heycosmo
  • 1,388
  • 11
  • 11
2

It's in platform/packages/apps/Music/src/com/android/music/TouchInterceptor.java. Here's a direct link:
https://android.googlesource.com/platform/packages/apps/Music/+/master/src/com/android/music/TouchInterceptor.java

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
CaseyB
  • 24,780
  • 14
  • 77
  • 112
1

Hint: download the android sources and have a look how the Music app (packages\apps\Music) implements this functionality.

yanchenko
  • 56,576
  • 33
  • 147
  • 165
  • Thank you for your answer. I have downloaded the source code and used it before but where can I find the Activity that uses this functionality? – wouter88 Dec 21 '09 at 14:12
  • @wouter88 Sorry, I haven't looked for that myself. Just search the sources for `*List*` to find what Activities reference ListViews. – yanchenko Dec 21 '09 at 16:24
  • that link appears to no longer function, and I can't find the source on the site. Do you know of another place I could find that source? – brainmurphy1 Sep 28 '16 at 16:02