public bool OnItemLongClick(AWidget.AdapterView parent, AViews.View view, int position, long id) { object selectedItem = null; //if (_element.ItemsSource.GetType().GetInterfaces().Any(x => x == typeof(IGroupedOrderable))) if (element.ItemsSource is IGroupedOrderableCollection grouped) { selectedItem = grouped.GetItemFromFlatIndex(id); } else { selectedItem = ((IList)element.ItemsSource)[(int)id]; } // Creating drag state DragItem dragItem = new DragItem(NormalizeListPosition(position), view, selectedItem); // Creating a blank clip data object (we won't depend on this) var data = ClipData.NewPlainText(string.Empty, string.Empty); // Creating the default drag shadow for the item (the translucent version of the view) // NOTE: Can create a custom view in order to change the dragged item view AViews.View.DragShadowBuilder shadowBuilder = new AViews.View.DragShadowBuilder(view); // Setting the original view cell to be invisible view.Visibility = AViews.ViewStates.Invisible; // NOTE: this method is introduced in Android 24, for earlier versions the StartDrag method should be used view.StartDragAndDrop(data, shadowBuilder, dragItem, 0); return(true); }
public bool OnItemLongClick(Android.Widget.AdapterView parent, Android.Views.View view, int position, long id) { var selectedItem = ((IList)_element.ItemsSource)[(int)id]; // Creating drag state DragItem dragItem = new DragItem(NormalizeListPosition(position), view, selectedItem); // Creating a blank clip data object (we won't depend on this) var data = ClipData.NewPlainText(string.Empty, string.Empty); // Creating the default drag shadow for the item (the translucent version of the view) // NOTE: Can create a custom view in order to change the dragged item view AViews.View.DragShadowBuilder shadowBuilder = new AViews.View.DragShadowBuilder(view); // Setting the original view cell to be invisible view.Visibility = ViewStates.Invisible; // NOTE: this method is introduced in Android 24, for earlier versions the StartDrag method should be used view.StartDragAndDrop(data, shadowBuilder, dragItem, 0); return(true); }
/// <summary> /// Handler for Long Click event from <paramref name="view"/> /// </summary> /// <param name="parent"> /// The parent list view . /// </param> /// <param name="view"> /// The view that triggered the long click event /// </param> /// <param name="position"> /// The position of the view in the list (has to be normalized, includes headers). /// </param> /// <param name="id"> /// The id of the item that triggered the event (must be bigger than 0 under normal circumstances). /// </param> /// <returns> /// The <see cref="bool"/> flag that identifies whether the event is handled. /// </returns> public bool OnItemLongClick(AWidget.AdapterView parent, AViews.View view, int position, long id) { var selectedItem = ((IList)_element.ItemsSource)[(int)id]; DragItem dragItem = new DragItem(NormalizeListPosition(position), view, selectedItem); var data = ClipData.NewPlainText(string.Empty, string.Empty); AViews.View.DragShadowBuilder shadowBuilder = new AViews.View.DragShadowBuilder(view); view.Visibility = ViewStates.Invisible; if (Build.VERSION.SdkInt >= BuildVersionCodes.N) { view.StartDragAndDrop(data, shadowBuilder, dragItem, 0); } else { view.StartDrag(data, shadowBuilder, id, 0); } return(true); }