Method for Android listview child control onclick to correctly obtain position

In actual development, we sometimes need to respond not only to the onItemClick of listview, but also to the click events of its child controls. At this time, we will

It is found that, due to reuse and other reasons, if you call position directly in getView () in the onClick event of the child control, there will be data or display malposition.

The reason is that the value of position is repeated or inaccurate. The way to solve this problem is to click every time the adapter loads data

Set a tag value for the control, which is set to the position corresponding to the current control, and then get the position in the click event gettag()

You can:

In getview():

The above is the Android listview sub control onclick introduced by Xiaobian to you. I hope it can help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>