New Tutorial: Implement Custom Drag & Drop - Recycler View to Other View in Xamarin.Android

JBeckJBeck USUniversity ✭✭✭
edited September 2016 in Presentations

I just finished creating a tutorial that shows how to implement custom drag and drop functionality on a Recycler View to enable both re-arranging items in the list, as well as dragging to Views outside the RecyclerView.

The full tutorial is here: https://sites.google.com/site/netdeveloperblog/xamarin/android/customdragdrop

Here is the tutorial overview

Xamarin.Android provides the ability to implement a RecyclerView helper class to rearrange a list of items. Additionally Xamarin.Android exposes a simple API to enable drag and drop between two View controls. Unfortunately, the RecyclerView helper class used to rearrange list items does not support dragging list items to controls outside of the RecyclerView control.

To enable dragging list items from a RecyclerView to other views, will create a layout file that uses a CardView control to gain access to long-press methods, and implement custom drag events. These drag events will support rearranging items within the RecyclerView, and also allow the user to drag list items to another view to delete them.

For the purposes of this demonstration, we will create a simple contact management application that allows a user to work with a list of existing Contact records, re-arrange and delete them by dragging to the appropriate area on the screen, tap on each contact to view the contact details, and simulate adding new contacts to the list.

This tutorial series covers the following activities:

  • Create a new Xamarin.Android project in Visual Studio
  • Adding the necessary NuGet packages for RecyclerView and CardView controls
  • Creating the Contact Model and View Model classes
  • Defining the necessary layout definitions for the main, list item, and drag box style definitions
  • Creating the View Holder class to set each list item's layout
  • Creating an Adapter class and customizing it with Drag functionality for the CardView controls
  • Creating the main Activity and customizing it to implement Drag and Drop functionality.

At the end of this tutorial you will have a fully functional, custom RecyclerView drag and drop implementation that extends the RecyclerView's drop range to any view control. With the knowledge you gain from this tutorial, you can go on to implement more custom drag and drop functionality in your own solution.
Source Code

On GitHub: https://github.com/C0D3Name/DragDropDroid

The source code for this tutorial series can be found on my GitHub page.

Attached is a screenshot of the project in-action.

Posts

Sign In or Register to comment.