Android ListView:如何使用自定义适配器中的 onClickListener 活动?

发布于 2024-09-30 00:01:09 字数 414 浏览 0 评论 0原文

我有一个使用自定义适配器的 listView 。每行包含一个按钮和一些其他视图。我希望能够单击按钮或行本身(以编辑单击的列表的项目)。

由于 这个问题,在活动中设置 onItemClickListener 不起作用

我认为, 我必须在适配器的 getView() 方法中设置一个 onClickListener 才能正常工作。 我想使用我的活动的 onClickListener,以便在单击该行时使用 startActivityForResult(),以便在项目编辑活动结束时将某些内容返回到我的活动。 我怎样才能做到这一点?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

马蹄踏│碎落叶 2024-10-07 00:01:09

您需要为添加到每一行的每个按钮添加一个 onclick 侦听器。执行此操作的最佳方法可能是在代码中创建自己的自定义布局,并且每次在适配器中创建新视图时,在布局代码中设置 onclick 侦听器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文