简体   繁体   中英

Android ListView: How to use the activity onClickListener from a custom Adapter?

I have a listView using a custom adapter. Each row contains a button and some other Views. I want to be able to click either on the button, or on the row itself (to edit the item of the list that is clicked).

Setting an onItemClickListener in the activity won't work because of this problem

I think I have to set an onClickListener in the getView() method of my adapter for it to work properly. I would like to use my activity's onClickListener, in order to use a startActivityForResult() when the row is clicked, in order to have something returned to my activity when the item edition activity is over. How can I do that?

Thanks!

You'll need to add an onclick listener to every button you add to every row. The best way to do this is probably to make your own custom layout in code, and every time you create a new view in your adapter, set the onclick listener in the layout code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM