Insights from Our Experts
Drag and Drop ExpandableListview in Android
I was searching for a drag and drop expandable listview for one of my applications, searched everywhere and found that there is no samples available in the net, but thanks to Eric Harlow.I got a sample drag and drop listview which could do the drag and drop operations for a simple listview, that didnt serve my purpose but that was something to start with.After a few hours of coding and customization I was able to update the drag and drop listview to a drag and drop expandablelistview.
The basic idea behind drag and drop can be divided into two sections, like updating the UI and updating the data. Updating UI starts with hiding the selected item and show a detached row with the same value as the hidden item, this will show that the selected item is ready to drag, now move the detached row over the list view based on the touchmove event, when the user takes the hand ie the touchup event or any other event that happens while dragging, get the current row at which user touched last , remove the detached row and do the data updation and invalidate the expandable listview, this will redraw the list based on the new set of data and the user will get a feeling that the item is dragged and dropped in the list.
So we are done with the theory part, now to implement this into codes I have included a sample project here, download and enjoy!! happy coding .