xamarin/Xamarin.Forms

ItemSelected/ItemTapped is not called in listview if an item view has TapGestureRecognizer (Android)

Open

#2,180 opened on Mar 24, 2018

View on GitHub
 (28 comments) (1 reaction) (0 assignees)C# (1,926 forks)batch import
a/listviewe/5 :clock5:help wantedm/high impact :black_large_square:p/Androidt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Description

ItemSelected (and ItemTapped) is not called on a listview, if it has label with TapGestureRecognizer:

<ListView.ItemTemplate> <DataTemplate> <ViewCell> ...... <Label1> <Label2> ...... <LabelX> <LabelX.GestureRecognizers> <TapGestureRecognizer Tapped="OnLabelXClick" CommandParameter="{Binding .}"/> </LabelX.GestureRecognizers>

Tapped 'OnLabelXClick' event is called on the LabelX, but the ItemSelected/ItemTapped event is not called in the ListView if you click outside of LabelX position.

This used to work in Xamarin.Forms.2.5.0.122203 (but with other issue: https://github.com/xamarin/Xamarin.Forms/issues/1331), but after upgrading to Xamarin.Forms.3.0.0.296286-pre2, ItemSelected/ItemTapped is not called.

This is only on Android. On iOS, works fine. Might be related to this fix: https://github.com/xamarin/Xamarin.Forms/issues/1331

Steps to Reproduce

  1. Create ListView in XAML
  2. Create ItemTemplate
  3. Make sure ItemTemplate ViewCell has several views, and at least a Label, which has TapGestureRecognizer
  4. In C# / ContentPage constructor add event handler to ListView.ItemSelected : _listView.ItemSelected += async (sender, e) => { ........}

Expected Behavior

If you click on a list item: -click on the label with TapGestureRecognizer: Tapped function is called [this works] -click on other place of the item in the list: ItemSelected/ItemTapped event triggered [this does NOT work]

Actual Behavior

If you click on a list item: -click on the label with TapGestureRecognizer: Tapped function is called -click on other place of the item in the list: ItemSelected/ItemTapped event is NOT triggered

Basic Information

  • Version with issue: Xamarin.Forms.3.0.0.296286-pre2
  • Last known good version: Xamarin.Forms.2.5.0.122203
  • IDE: VS2017 15.6.4
  • Platform Target Frameworks:
    • iOS: NOT REPRODUCIBLE, works fine. (11.1)
    • Android: 8.1
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Contributor guide