Suresh
Suresh

Reputation: 9605

Difference between onItemClickListener and OnItemSelectedListener of AdapterView

What is the difference between these two listeners,documentation says :

OnItemSelectedListener - Interface definition for a callback to be invoked when an item in this view has been selected.

OnItemClickListener - Interface definition for a callback to be invoked when an item in this AdapterView has been clicked.

Selection,Click aren't these equal on touch screen?

Upvotes: 48

Views: 13765

Answers (3)

khaoula1305
khaoula1305

Reputation: 74

Android makes a distinction between selection events and click events. Widgets based off of the “spinner” paradigm — including Spinner and Gallery — treat everything as selection events. Other widgets — like ListView and GridView — treat selection events and click events differently. For these widgets, selection events are driven by the pointing device, such as using arrow keys to move a highlight bar up and down a list. Click events are when the user either “clicks” the pointing device (e.g., presses the center D-pad button) or taps on something in the widget using the touchscreen.

(source: Excerpt from "The Busy Coder's Guide to Android Development" Version 3.8)

Upvotes: 1

user1611552
user1611552

Reputation: 621

AdapterView.OnItemSelectedListener is invoked only when the newly selected position is different from the previously selected position or if there was no selected item.

However AdapterView.OnClickListener is invoked even you click the same item everytime.

http://developer.android.com/reference/android/widget/AdapterView.OnItemSelectedListener.html

Upvotes: 38

Bryan Denny
Bryan Denny

Reputation: 27596

OnItemSelectedListener is used for Spinners, and OnItemClickListener is used for ListViews.

Upvotes: 58

Related Questions