Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between onClickListener and onItemClickListener

what is the difference between onClickListener and onItemClickListener in Android ListViews ? And what are the different implementations of these ?

like image 909
Chamath Avatar asked Jun 15 '12 04:06

Chamath


People also ask

What is the use of OnClickListener?

In Android, the OnClickListener() interface has an onClick(View v) method that is called when the view (component) is clicked. The code for a component's functionality is written inside this method, and the listener is set using the setOnClickListener() method.

What is Onitemclick?

OnItemClickListener is an interface and interface has a property that the class which implements it must implement its unimplemented method(s) (because interface contains declaration of methods not implementation).


1 Answers

ListView has an Item Click listener for each row of the listview but the onClickListener is for the whole listview no matter which ever row you click the onClick and onItemClickListener is called but the values that come with each method are different.

OnItemClickListener you can use for lets say going to a particular activity when a particular row is touched.

OnClickListener you can check if the listview has received a touch by the user so do you want to refresh the list? or change the scrollbar's view or do something with the listview as a whole unit.

like image 154
Sana Avatar answered Oct 07 '22 13:10

Sana