Вы можете добавить TapGestureRecognizer
в ListView
в Xml
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lvQueue"/>
в коде позади
ListView listView = FindViewById<ListView>(Resource.Id.lvQueue); ;
listView.SetOnTouchListener(new GestureListener());
public class GestureListener : Java.Lang.Object, View.IOnTouchListener
{
public bool OnTouch(View v, MotionEvent e)
{
// do something you want
return true;
}
}
Обновление
Поскольку событие касания всегда вызывается перед действием щелчка элемента, поэтому, если вы хотите добавить событие щелчка только в пустое пространство страницы, когда элементов в ListView
немного. Мы могли бы определить другое представление под списком и установить событие щелчка как обходной путь.
in xml
Поместить ListView в LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<ListView
android:id="@+id/listView"
android:background="@android:color/holo_blue_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" // set the weight as 1 , so that it will warp the white space of the screen auto
android:background="@android:color/holo_blue_light" // set the background color the same with thelistview
android:id="@+id/view"/>
</LinearLayout>
в коде позади
TextView view = FindViewById<TextView>(Resource.Id.view);
view.Click += View_Click;
private void View_Click(object sender, EventArgs e)
{
//...
}