Эту функцию можно реализовать, поместив представление списка в действие, не используя ListActivity. А затем установите свойство android: listSelector для списка в «@android: color / transparent». Итак, демо-код выглядит так:
MainActivity.cs
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using System;
using Android.Views;
namespace App46
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : Activity
{
string[] items;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
items = new string[] { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
ArrayAdapter adapter = new ArrayAdapter<String>(this, Resource.Layout.list_item, items);
ListView lv = FindViewById<ListView>(Resource.Id.listView1);
lv.Adapter = adapter;
lv.ItemLongClick += delegate (object sender, AdapterView.ItemLongClickEventArgs args)
{
Toast.MakeText(Application, ((TextView)args.View).Text, ToastLength.Short).Show();
};
}
}
}
activity_main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView1"
android:listSelector="@android:color/transparent"/>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp">
</TextView>