question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListView item selection without gesture recognizers fails on Android

See original GitHub issue

It seems ListView elements won’t invoke the ItemSelected and ItemTapped callbacks, and sometime they just do it the first time the item is tapped.

To reproduce the issue change the class BuildCard in CarouselSampleListView.cs as follows:

private object BuildCard(Color color)
{
	var list = new ListView
	{
		BackgroundColor = color,
		ItemTemplate = new DataTemplate(() =>
		{
			var label = new Label
			{
				TextColor = Color.White
			};
			label.SetBinding(Label.TextProperty, nameof(ListItemModel.Text));

			var content = new ContentView();
			content.Content = label;

			var tapGesture = new TapGestureRecognizer();
			tapGesture.SetBinding(TapGestureRecognizer.CommandProperty, nameof(ListItemModel.Command));
			//content.GestureRecognizers.Add(tapGesture); <-- comment this to disable the gesture recognizer

			return new ViewCell
			{
				View = content
			};
		})
	};
	list.SetBinding(ItemsView<Cell>.ItemsSourceProperty, nameof(ListCardModel.Items));

	// add these callbacks
	list.ItemSelected += (sender, e) =>
	{
		var listView = (ListView)sender;
		if (listView.SelectedItem == null)
		{
			return;
		}
		Application.Current.MainPage.DisplayAlert("Selected", null, "Ok");
		listView.SelectedItem = null;
	};
	list.ItemTapped += (sender, e) =>
	{
		Application.Current.MainPage.DisplayAlert("Tapped", null, "Ok");
	};

	return new ContentView
	{
		Margin = new Thickness(30, 20),
		Content = list
	};
}

I’m using Android version 5.0.1 running on an Acer Iconia B1-770 with the version of XF and CardView in the master branch

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AndreiMisiukevichcommented, Jul 9, 2018

will be available in next release =)

1reaction
AndreiMisiukevichcommented, Jul 7, 2018

Wow, fantastic. I will adjust this fix. Really too strange issue)

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Is there an event for when I click the ListView where ...
You could add TapGestureRecognizer on the ListView. in Xml. <ListView android:layout_width="match_parent" android:layout_height="wrap_content" ...
Read more >
TapGestureRecogniser does not work inside a ListView ...
I have an Android 9 Xamarin Forms app (no iOS) in which I'm binding a ListView to an ObservableCollection<Comp>. Inside each Comp instance ......
Read more >
Swiping in Xamarin ListView (SfListView)
Swipe views are displayed when swiping from left to right or right to left (for Horizontal orientation, top to bottom or bottom to...
Read more >
ListView | Android Developers
A list view is an adapter view that does not know the details, such as type and ... When set to true, the...
Read more >
Question - XAML - ItemTapped no working
Hi I am unable to get ItemTapped working. I am using VS 2019/XAML/C#. When I click on a selected item, nothing happens.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found