You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
ItemSelected/ItemTapped is not called in listview if an item view has TapGestureRecognizer (Android)
#2180
ItemSelected/ItemTapped is not called in listview if an item view has TapGestureRecognizer (Android)
zoli13
opened this issue
Mar 24, 2018
· 28 comments
help wanted
We welcome community contributions to any issue, but these might be a good place to start!
m/high impact ⬛
p/Android
t/bug 🐛
up-for-grabs
We welcome community contributions to any issue, but these might be a good place to start!
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:
#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:
#1331
Steps to Reproduce
Create ListView in XAML
Create ItemTemplate
Make sure ItemTemplate ViewCell has several views, and at least a Label, which has TapGestureRecognizer
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:
ListViewBug.zip
Sample attached to reproduce.
If you run, and you click on any list item (outside of text1 label), you can see that the "OnItemSelected" is
not
called,
If you remove the <Label.GestureRecognizers> from the ListViewBug\MainPage.xaml , "OnItemSelected" is called properly.
changed the title
ItemSelected is not called in grouped listview if an item view has TapGestureRecognizer (3.0.0.296286-pre2)
ItemSelected is not called in listview if an item view has TapGestureRecognizer (3.0.0.296286-pre2)
Mar 27, 2018
I am having the same issue when using Xamarin.Forms 2.5.1.392594-pre3.
Removing the GestureRecognizer from a child Grid inside the ItemTemplate ViewCell worked to get the OnItemSelected called.
This is only occurring on Android. It works fine on iOS targeting iOS 11.2.
IDE: VS2017 15.6.4
changed the title
ItemSelected is not called in listview if an item view has TapGestureRecognizer (3.0.0.296286-pre2)
ItemSelected is not called in listview if an item view has TapGestureRecognizer (3.0.0.296286-pre2 / Android)
Apr 10, 2018
changed the title
ItemSelected is not called in listview if an item view has TapGestureRecognizer (3.0.0.296286-pre2 / Android)
ItemSelected/ItemTapped is not called in listview if an item view has TapGestureRecognizer (Android)
May 11, 2018
Will this be fixed in a new version for Xamarin.Forms 2.5.1? That would be great! Because XF 3.0 requires VS 2017 ...
[offtopic]
I find it funny, that a fix for a bug introduces a new bug. Including a
ListView_ItemTapped
method would immediately show that error in the Github1331 project.
The issue is reported two months ago and since then the fix isn't planned nor the issue solved. The origin issue is here since six months! Xamarin.Forms seems still not be really useful for productive environments ...
[/offtopic]
Normally, if user taps on view which has TapGestureRecognizer, that should be called.
Otherwise, if user taps on view which has NO TapGestureRecognizer / or taps outside of any view within the item, then ItemSelected/ItemTapped should be called.
Other idea could be that ItemTapped event receives the tapped view as param (which is NULL if tapped on "empty" area). This case, no need for TapGestureRecognizer.
class ItemTappedEventArgs { object Group, object Item)
class ItemTappedEventArgs { object Group, object Item, object View)
I've got a few TapGestureRecognizers within a viewcell, they can co-exist.
On iOS, everything works - tapping viewcell will invoke "ItemSelected" and tapping on the GestureRecognizers will invoke the various commands.
On Android, only the GestureRecognizers work, the viewcell "ItemSelected" no longer functions.
Both iOS and Android were working on XF 2.5. I upgraded to 3.1.0 last night and after testing that's the one thing that doesn't work on Android.
Confirming that this issue still exists in 3.1.0.697729. I didn't have any luck with effects. So I added an image to my viewcell with a Image.tapGesture and removed the ViewCell.ContextActions. This had the ItemSelected work again and the tap gesture on the image works. Maybe that will help someone.
Hey, thanks for the reply. I'd be happy to see the code. Since I never got it working (:
OK no problem. I'll try to explain it all here.
Since the ListView is working with iOS, I didn't want to modify that to have to work with long / short press and keep the swipe mechanism so for that I created two DataTemplates, one for iOS and one for Android:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/templates/data-templates/creating
The following line will choose which template to use based on the platform....
<local:PlatformSelector x:Key="PlatformSelector" isPlatformiOS="{StaticResource iOSPlatformTemplate}" isPlatformAndroid="{StaticResource AndroidPlatformTemplate}" />
and on the ListView itself...
<ListView ItemTemplate="{StaticResource PlatformSelector}" ... >
code behind:
public class PlatformSelector : DataTemplateSelector
public DataTemplate isPlatformiOS { get; set; }
public DataTemplate isPlatformAndroid { get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
return Device.RuntimePlatform.Equals(Device.iOS) ? isPlatformiOS : isPlatformAndroid;
On the Android ListView viewcell I had a StackLayout and attached the effect:
<StackLayout.Effects>
<effects:LongPressedEffect/>
</StackLayout.Effects>
The code for effect, I used this example:
https://alexdunn.org/2017/12/27/xamarin-tip-xamarin-forms-long-press-effect/
and code from here: https://github.com/lywyn/LongPressedTestApp
If you're stuck, give me a shout.
For me, the ItemSelected/ItemTapped is not called in listview if an item view has TapGestureRecognizer and ContextActions. Xamarin.Forms 3.3.0.912540
I'm adding a repro project
FastScroll.zip
MJunak, IgorKravchenko10, DennisWelu, RanKarat, and joseluisct reacted with thumbs up emoji
hartez and joseluisct reacted with hooray emoji
All reactions
For me, the ItemSelected/ItemTapped is not called in listview if an item view has TapGestureRecognizer and ContextActions. Xamarin.Forms 3.3.0.912540
I'm adding a repro project
FastScroll.zip
I have same issue https://forums.xamarin.com/discussion/145672/listview-itemselected-and-itemtapped-not-working-with-contextactions/
[Bug] GestureRecognizer inside ListView with ViewCell.ContextActions breaks the ListView ItemSelected Event ( Android Only )
#6386
up-for-grabs
We welcome community contributions to any issue, but these might be a good place to start!
labels
Jul 2, 2019
I have a reproduction case for this issue: A ListView containing items that have a gesture recognizer as well as a context action. In this case, the ItemTapped event is never called:
https://gist.github.com/vividos/d2819d8e3890413593c04e9d622ceee8
Add this file to the Xamarin.Forms.Controls.Issues.Shared project and start the Xamarin.Forms.ControlGallery.Android project.
I hope this helps to find and fix the issue.
help wanted
We welcome community contributions to any issue, but these might be a good place to start!
m/high impact ⬛
p/Android
t/bug 🐛
up-for-grabs
We welcome community contributions to any issue, but these might be a good place to start!