I'm looking for a way to get an ItemLongPress similar to the ItemTapped that is provided for android only (but accessible in through Forms).
I tried making a custom renderer and it is being used (I put a breakpoint in an override of the OnElementChanged in the customer renderer and it's being called), but I'm not getting any touch events. I tried overriding the OnTouchEvent (breakpoint never hits) and I tried Control.SetOnLongClickListener inside the OnElementChanged event (after setting LongClickable = true), but the breakpoint in my new Long Click Listener never hits.
Code snippets from the custom renderer (not entire code, but this is where I've set breakpoints):
protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Telerik.XamarinForms.DataControls.RadListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null) {
if (Control != null) {
Control.Clickable = true;
Control.SetOnTouchListener(RadTouchListener.Instance.Value);
Control.LongClickable = true;
Control.SetOnLongClickListener(RadLongClickListener.Instance.Value);
}
}
}
private class RadLongClickListener : Java.Lang.Object, Android.Views.View.IOnLongClickListener
{
public static readonly Lazy<RadLongClickListener> Instance = new Lazy<RadLongClickListener>(() => new RadLongClickListener());
public bool OnLongClick(Android.Views.View v)
{
var renderer = v.Tag as ExtendedRadListRenderer;
((ILongPressController)renderer?.Element)?.SendLongClicked();
return true;
}
}
public override bool OnTouchEvent(MotionEvent e)
{
return base.OnTouchEvent(e);
}