Hello,
Welcome to our Microsoft Q&A platform!
You can use Custom Renderers to achieve this.
In android:
[assembly: ExportRenderer(typeof(CustomListView), typeof(CustomListViewDroid))]
namespace FormsListViewSample.Droid
{
public class CustomListViewDroid: ListViewRenderer
{
public CustomListViewDroid(Android.Content.Context context):base(context) {
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
var view = (CustomListView)Element;
this.Control.ItemLongClick += (s, args) =>
{
this.Control.SetItemChecked(args.Position, true);
Java.Lang.Object item = this.Control.GetItemAtPosition(args.Position);
view.OnLongClicked(item.GetType().GetProperty("Instance").GetValue(item));
};
}
}
}
}
In forms:
public class CustomListView:ListView
{
public event EventHandler LongClicked;
public void OnLongClicked()
{
if (LongClicked != null)
LongClicked(this, new ItemTappedEventArgs(this, this.SelectedItem));
}
public void OnLongClicked(object v)
{
Log.Warning("test", "OnLongClicked is triggered");
}
}
Refer: https://forums.xamarin.com/discussion/1013/catching-long-presses-on-a-list-view
And there is a similar thead about this, you can check it:
https://stackoverflow.com/questions/62895490/long-press-event-on-listview-items-in-xamarin-forms
https://www.c-sharpcorner.com/article/longpress-event-for-image/
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.