[英]Android ListView: How to use the activity onClickListener from a custom Adapter?
I have a listView using a custom adapter. 我有一个使用自定义适配器的listView。 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 由于此问题 ,在活动中设置onItemClickListener无效
I think I have to set an onClickListener in the getView() method of my adapter for it to work properly. 我认为我必须在适配器的getView()方法中设置onClickListener才能使其正常工作。 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.
我想使用活动的onClickListener,以便在单击行时使用startActivityForResult(),以便在项目版本活动结束时将某些内容返回到我的活动中。 How can I do that?
我怎样才能做到这一点?
Thanks! 谢谢!
You'll need to add an onclick listener to every button you add to every row. 您需要向添加到每一行的每个按钮添加一个onclick侦听器。 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.
最好的方法可能是在代码中创建自己的自定义布局,并且每次在适配器中创建新视图时,都在布局代码中设置onclick侦听器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.