在列表项中使用微调器不会触发OnItemClik [英] Using Spinner in a List Item does not trigger the OnItemClik

查看:55
本文介绍了在列表项中使用微调器不会触发OnItemClik的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView,其中每个列表项都有一个Spinner.通过在Activity中实现OnItemSelectedListener并将其添加到适配器的GetView()中,我已经成功地向每个微调器添加了OnItemSelectedListener.

I have a ListView in which each List item has a Spinner. I have successfully added an OnItemSelectedListener to each spinner by implementing OnItemSelectedListener in the Activity and adding it in the GetView() of the adapter.

问题是,我还必须为Activity中的ListView实现OnItemClickListener.我已经做到了,但是没有为该项目触发该事件单击普通列表项.但是,对于列表部分标题(没有微调框),它会被触发.

The problem is, I also have to implement OnItemClickListener for the ListView in the Activity. I have done that, but the event is not getting fired for the Item Click on normal list items. But, it is getting fired for the list section headers(which do not have the spinners).

我如何也可以触发列表项的事件?

How can I trigger the event for the List items as well?

推荐答案

尝试一下,

将以下属性添加到Spinner元素,

add the below property to your Spinner element,

android:focusable=false

问题是因为Spinner是具有clickable属性的元素,它将控制您的click事件,因此您的listview将没有机会处理click事件.通过添加以上属性,您可以使微调框和列表视图都可以使用.

The problem is because spinner is a element with clickable property, which will take the control of your click events and hence your listview wont get the chance to handle the click events. By adding the above property you can make both the spinner and your listview to get worked.

如果仍然无法正常运行,请尝试将其添加到listview元素xml的最顶部布局中,

If it still doesn't work then try adding this to the top most layout of your listview element xml ,

android:descendantFocussability=blocksDescendants 

这篇关于在列表项中使用微调器不会触发OnItemClik的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆