Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - drag and drop - list rearrange

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?

like image 377
wouter88 Avatar asked Dec 21 '09 13:12

wouter88


People also ask

Does Android have drag and drop?

The Android drag and drop framework enables you to add interactive drag and drop capabilities to your app. With drag and drop, users can copy or move text, images, objects—any content that can be represented by a URI—from one View to another within an app or, in multi-window mode, between apps.

How do I drag and drop on Android tablet?

A double tap and hold allows you to grab and then drag. A two-finger tap acts as a right click. A two-finger drag reproduces the mouse wheel scrolling action.

How do I drag view on Android?

FrameLayout is a ViewGroup where if you add a child view to it, the child view will be positioned to the top left corner of the screen. So you can wrap all the UI components in a ViewGroup e.g LinearLayout or ScrollLayout and add it under the FrameLayout. Then add button/view which you want to drag.


5 Answers

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

like image 93
ericharlow Avatar answered Oct 01 '22 13:10

ericharlow


Pay special attention to this one

com.android.music.TouchInterceptor

like image 40
Bo. Avatar answered Oct 01 '22 13:10

Bo.


You can also try my recent implementation here:

  • https://github.com/bauerca/drag-sort-listview

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.

like image 45
heycosmo Avatar answered Oct 01 '22 13:10

heycosmo


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

like image 21
CaseyB Avatar answered Oct 01 '22 14:10

CaseyB


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

like image 41
yanchenko Avatar answered Oct 01 '22 12:10

yanchenko