Skip to content
Advertisement

.OnClickListener versus .OnChildClickListener

I know that (View.)OnClickListener is called whenever a view has been clicked on.

What I don’t understand properly is, what OnChildClickListener does. I also wanted to know the difference between them.

P.S. I have read Android’s documentation on OnChildClickListener but I am not able to grasp the concept.

Advertisement

Answer

To expand on Tenfour04’s comment, OnChildClickListener is actually ExpandableListView.OnChildClickListener, which is part of ExpandableListView. It’s used with ExpandableListView.setOnChildClickListener to listen to clicks on the children of groups in the expandable list view. For the groups themselves, there’s ExpandableListView.OnGroupClickListener. These are attached to the parent ExpandableListView in place of putting an OnClickListener on each individual item.

View.OnClickListener is, as you note, for listening to clicks on any View.

Advertisement