简体   繁体   English

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

[英]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.

相关问题 Android ListView onClickListener自定义适配器 - Android ListView onClickListener Custom Adapter 自定义适配器不刷新android中onclicklistener的listview - custom adapter do not refresh the listview for onclicklistener in android Android:如何将数据从适配器传递到OnClickListener的Main Activity - Android: How to pass Data from an Adapter to the Main Activity from a OnClickListener Android listview onclicklistener活动 - Android listview onclicklistener activity 如何在ANDROID自定义Listview适配器中使用setonitemclicklistener - How to use setonitemclicklistener in ANDROID custom Listview Adapter Android ListView适配器OnClickListener问题 - Android ListView Adapter OnClickListener issue 从onClickListener中的自定义适配器创建的ListView中删除行 - Delete row from ListView created by Custom Adapter in onClickListener 具有自定义适配器的android listview冻结活动 - android listview with custom adapter freezes activity 如何为绑定到自定义适配器的 ListView 设置 onClickListener? - How do I set up onClickListener for ListView binded to custom adapter? 如何将onClickListener添加到由自定义Cursor适配器填充的列表视图中的图像视图? - How to add onClickListener to a imageview in a listview populated by custom Cursor adapter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM