Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between the ItemTapped and the ItemSelected event on a ListView in Xamarin.Forms?

A ListView in Xamarin.Forms has two events, which seem to be exactly the same: ItemTapped and ItemSelected

There isn't really any documentation about these, so what exactly is the difference?

like image 748
Flagbug Avatar asked Jun 27 '14 12:06

Flagbug


4 Answers

ItemSelected is a state while ItemTapped is a motion event. All views can be tapped and if I remember correctly all views can be selected (or at least activated there is a subtle difference), the two don't have to go together but they usually do.

For example you'd have an item's selected state toggled each time a tapped motion event has occurred. Once again just to make it more clear you can associate the changes of the selected state to whatever you need whether it's a motion event like tapping or long pressing or double tapping and so on or to some other event or logic.

Hope it helps and good luck!

like image 129
Alex.F Avatar answered Oct 21 '22 14:10

Alex.F


ItemTapped should occur every time you click on an item, while ItemSelected every time the selected item has changed.

Basically

  • tapping two times the same item should fire two times ItemTapped, and only once ItemSelected
  • tapping two times, on different items, should fire ItemTapped two times, and ItemSelected two times
like image 39
Massimo Prota Avatar answered Oct 21 '22 13:10

Massimo Prota


ItemSelected occurs first. ItemTapped occurs second.

like image 1
Guy Micciche Avatar answered Oct 21 '22 15:10

Guy Micciche


One major difference worth noting is how they work when the SelectionMode="None"

<ListView ... SelectionMode="None" />

When set to "None"...the ItemSelect event will not fire and SelectedItem property remains null.

But ItemTapped events will continue to fire as expected.

ListView interactivity

like image 1
Chris Catignani Avatar answered Oct 21 '22 13:10

Chris Catignani