23 comments on “Re-Order ListView Items with Drag & Drop – II

  1. Can, nice job. But I think you are missing something within the implementation of method “InsertOntoView()”.


  2. Pingback: Dew Drop - March 19, 2018 (#2686) - Morning Dew

  3. Hey Can… thanks for these posts. Do you think it would be possible for you to have all the classes and interfaces in one ZIP file for us to download?

    I am stuck on the DragItem class where I currently can’t figure out where _element, _translatedItems and _listView is coming from.



  4. Hello Can, a great post and I just need something like that for a project, but I don’t have much experience in xamarin and I wanted to ask you if I could see the whole code somehow. I’d really appreciate the help.


  5. Hi Can Bilgin,

    StartDragAndDrop Works only in Android 7 and above.
    Now StartDrag is depreceated,how to use drag and drop in Android 6?
    Any help!

    Thank you


  6. Hi Can Bilgin, In what version of Xamarin.Forms did you build this ? for version, there is a weird issue in release mode only. In debug mode, it works fine. The underlying type of _listView.Adapter inside the constructor of DragListAdapter, is different. Due to this, an exception is thrown in this line:

    _listAdapter = ((AWidget.IWrapperListAdapter)_listView.Adapter).WrappedAdapter;

    Release Mode Type of adapter: Android.Widget.IListAdapterInvoker [throws InvalidCastException]
    Debug Mode Type of adapter: Android.Widget.HeaderViewListAdapter [works]


  7. Can, this code is fantastic but it really would be great if we could see the entire source on GitHub. Helps to have a little context around everything.

    Also, i agree with Maurice. You have a DragDropEnabled property, but it’s not being used. Seems like it would be effective at the top of OnItemLongClick.


  8. Hi, I have two Listviews in a same Content page. Both with your drag drop support enabled. Top list has 2 items and bottom list has 5 items. When I drag, say item 4 from bottom list and drop it into index 2 of same listview it blows up because it thinks I’m dropping the item into top view list and indexes are out of bounds. Should your implementation support multiple ListViews in same page? Thanks


  9. @Can Bilgin, sorry, I can’t edit my previous comment. This is working great in Nexus 9 (Android 7.1.1), but for device Samsung Galaxy Note5 (Android 5.1.1), drag is working, but when I drop it is disappeared.I felt that this problem was due to Startdraganddrop() method incompatibility in OnItemLongClick event handler for devices later than Android API 24 as you mentioned. So, I used an if-else to use startdrag for android versions earlier than API 24 to use startdrag() and versions later than API 24 to use startdraganddrop() method, still the item disappears on dropping in Note 5. Any help would be appreciated, thanks in advance. NOTE: the other change I made in the code you have posted here was : _listAdapter = _listView.Adapter; instead of _listAdapter = ((AWidget.IWrapperListAdapter)_listView.Adapter).WrappedAdapter; I got “Specified cast is invalid” error, so I put without casting, is this the problem? Kindly help. Thanks again


  10. @Can Bilgin, thanks for this amazing contribution!, it works really well. I have only 2 questions I need some guidance if you have time.
    1)on Android it seems the view you drag always gets grabbed from the “middle”, giving an impression of it shifting too much outside of the screen, do you know how we can make it a little bit more centered in the screen?
    2)On Android I’d like to add an image with the classic “drag” picture, but it seems you can’t drag from there, how can we make it so that the drag event gets activated when you do the long press on the image?


  11. @Can Bilgin in your DragListAdapter,

    public DragListAdapter(AWidget.ListView listView, ListView element)
    _listView = listView;
    // NOTE: careful, the listAdapter might not always be an IWrapperListAdapter
    _listAdapter = ((AWidget.IWrapperListAdapter)_listView.Adapter).WrappedAdapter;
    _element = element;

    you have a note about the list adapter might not always be an IWrapperListAdapter. We are getting an invalid cast exception for this, but it should be fine as it is coming from a ListView. Any idea why this might happen?


  12. // NOTE: careful, the listAdapter might not always be an IWrapperListAdapter
    _listAdapter = ((AWidget.IWrapperListAdapter)_listView.Adapter).WrappedAdapter;

    at this line .


  13. // NOTE: careful, the listAdapter might not always be an IWrapperListAdapter
    _listAdapter = ((AWidget.IWrapperListAdapter)_listView.Adapter).WrappedAdapter;

    at this line . app crashing


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s