ListView item selection without gesture recognizers fails on Android
See original GitHub issueIt 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:
- Created 5 years ago
- Comments:11 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
will be available in next release =)
Wow, fantastic. I will adjust this fix. Really too strange issue)