Difference in listview.setOnItemClickListener and row.setOnClickListener

假装没事ソ 提交于 2019-12-04 08:30:55

Or are they exactly the same?

In first approach you will create for each row own listener e.q. you have 100 rows so you'll have 100 listeners that is not good at all. In second approach you will create one listener for whole ListView.

android.widget.AdapterView.OnItemClickListener
android.view.View.OnClickListener

How you can see, first is more comfortable and directly designated for dealing with adapter widgets like ListView is. Also this approach is generally recommended and used.

You have connection with each row via parameters of onItemClick() method and code is more human-readable and it's clearer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!