DevBytes: ListView Cell Dragging and Rearranging

Android Developers · 96K views · 2013 · 11:49

Open on YouTube

Software practice, open source & careersUX & UI designSoftware (other)tutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the canonical answer to how to implement drag-and-drop reordering in an Android ListView, and as the source of the DynamicListView code that many questions build on or debug.

Recommended by 7 people across 7 different months, 2013 to 2016.

What it is

An Android Developers DevBytes episode showing how to build a custom ListView (DynamicListView) that lets users long-press, drag and drop rows to reorder the underlying data, with animated cell swapping. Sample code is provided as a downloadable zip.

What people said

Recommends Arun C · 2013-08 · Stack Overflow · on “Android List View Drag and Drop sort”

Am adding this answer for the purpose of those who google about this.. There was an episode of DevBytes ( ListView Cell Dragging and Rearranging [this video] ) recently which explains how to do this You can find it here [this video] also the sample code is available here [LINK] . What this code basically does is that it creates a dynamic listview by the extension of listview that supports cell dragging and swapping. So that you can use the DynamicListView instead of your basic ListView and that's it you have implemented a ListView with Drag and Drop.

Recommends rarp · 2013-09 · Stack Overflow · on “Android control for simple drag and drop boxes”

A combination of this [this video] and this [LINK] should get you started. I've never done anything like it, so I'm not even going to try and post an answer.

Recommends Dominic · 2013-11 · Stack Overflow · on “How to animate view and meanwhile preserve view in its original location during the animation”

You can create a Bitmap of your View, do some transformations on your Bitmap and then animate it instead of the View. This pattern is often used when dragging views around. There is on episode of the DevBytes series which explains this pretty good. [this video]

Recommends Sotti · 2014-01 · Stack Overflow · on “drag and drop of items in listview in android?”

In August 2013 Google uploaded a very simple example with a video and the code. Video: [this video] code: [LINK] Hope it helps.

Recommends Krylez · 2014-05 · Stack Overflow · on “Problems with TouchListView and Drag and Drop?”

You'll need to include the file that declares those attributes. For class you're using, this is the cwac_touchlist_attrs.xml file. Keep in mind that TouchListView is deprecated and no longer maintained. Here's a good alternative: [this video]

Recommends Markus · 2014-08 · Stack Overflow · on “Drag and drop within RecyclerView”

Pretty much the same way you would do it with a listview: [this video] Start by copying their implementation and you will find there are only a few small differences

Recommends The Original Android · 2015-04 · Stack Overflow · on “Android List View with BaseAdapter Drag and Drop sort”

There are working set of codes for Drag-and-Drop using ListView by a starting developer in Google team @ ListViewDraggingAnimation zip [LINK] . There is a video explaining the internal code @ ListView Cell Dragging and Rearranging [this video] . You don't have to understand the code in DynamicListView. Sample code to start: StableArrayAdapter adapter = new StableArrayAdapter(this, R.layout.text_view, mCheeseList); DynamicListView listView = (DynamicListView) findViewById(R.id.listview); listView.setCheeseList(mCheeseList); listView.setAdapter(adapter); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); Notes: For calling StableArrayAdapter constructor using " this " object works in an Activity.

Cites cryptic'l · 2013-10 · Stack Overflow · on “App Runs in Emulator but Gives NoClassDefFound Error When Trying to Run on Device”

I am testing my app for the first on an android device (galaxy s3 mini) which has been tested several times in the emulator. The app contains a custom List View (DynamicListView: [this video] ). Code for this class with a demo app can be found here [LINK] The extended listview class is in the same package as my main activity and added in the main activity layout, but after app is installed and about to start logcat prints that the class cannot be found. I've searched the web and don't seem to find a solution or even anyone with similar problem. I feel stuck with this problem as I don't really know how to go about fixing it and would appreciate any help offered. The following is logged early on...

Cites Skartt · 2013-11 · Stack Overflow · on “Drag and drop ListView without library”

The adapter take the array and fix it. The array are immutable in java, so there is an UnsuportedOperationException during the insertion. When I used a list, the exception was resolved, but there was a lot of bugs, with the drag and drop events. I saw that google made a tutorial about drag and drop list in august 2013. They don't use their own framwork... I think that's not adapted for list. I post the link if someone is interested : Drag and drop tutorial [this video]

Cites user1178729 · 2014-05 · Stack Overflow · on “Reorderable ListView via drag and drop”

There are several questions regarding this topic, but they are all very old, from 2010: Reorder elements of ListView by dragging [LINK] reordering of listview items by drag and drop using android [LINK] And also, I checked this DevBytes video out: [this video] The problem with this video is that it just allows to use long press on items to drag, but does not allow to have a "grip" or a "dragging handle". What is the correct way to acihieve this? EDIT I proceeded and tried to use the DevBytes approach, with the following code: package com.autrilla.shoppinglist; import android.animation.*; import android.content.Context; import android.graphics.*; import android.graphics.drawable.BitmapDrawable; im