Luis A. Florit
Luis A. Florit

Reputation: 2609

Which: ListView.setOnItemClickListener or TextView.setOnClickListener?

I have a ListView with a custom adapter that only has a TextView, and I want to set a click listener for it.

Which one I should choose: ListView.setOnItemClickListener outside of the custom adapter, or TextView.setOnClickListener inside the custom adapter's getView()? And why?

Thanks!

L.

Upvotes: 0

Views: 526

Answers (2)

Eddy
Eddy

Reputation: 589

adding onClickListener to views in the getView() method is using when you have 2 or more views that should have their own onClickListener,so for your is better onItemClickListener

Upvotes: 1

Sipka
Sipka

Reputation: 2311

You should definitely use ListView.setOnItemClickListener

  1. Because when you press the list item it gives feedback that you pressed it (like glow background or something)
  2. You are controlling your data from outside of your list, and therefore you have better vision on the objects you are controlling
  3. More object oriented
  4. In my opinion it's easier
  5. If you have only one view in a list row then why bother setting the click listener on the TextView instead of the row?

Upvotes: 5

Related Questions