问题
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.
回答1:
You should definitely use ListView.setOnItemClickListener
- Because when you press the list item it gives feedback that you pressed it (like glow background or something)
- You are controlling your data from outside of your list, and therefore you have better vision on the objects you are controlling
- More object oriented
- In my opinion it's easier
- If you have only one view in a list row then why bother setting the click listener on the TextView instead of the row?
回答2:
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
来源:https://stackoverflow.com/questions/20446195/which-listview-setonitemclicklistener-or-textview-setonclicklistener