ListView的项目无法点击与Horizo​​ntalScrollView内 [英] ListView items not clickable with HorizontalScrollView inside

查看:109
本文介绍了ListView的项目无法点击与Horizo​​ntalScrollView内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的的ListView 。每个项目看起来是这样的:

I have quite a complicated ListView. Each item looks something like this:

> LinearLayout (vertical)
  > LinearLayout (horizontal)
    > include (horizontal LinearLayout with two TextViews)
    > include (ditto)
    > include (ditto)
  > TextView
  > HorizontalScrollView (this guy is my problem)
    > LinearLayout (horizontal)

在我的活动,在创建项目时( getView()称)我添加动态的TextView 取值到的LinearLayout Horizo​​ntalScrollView (除了填充其他的,更简单的东西了)。令人惊讶的,性能pretty的好。

In my activity, when an item is created (getView() is called) I add dynamic TextViews to the LinearLayout inside the HorizontalScrollView (besides filling the other, simpler stuff out). Amazingly, performance is pretty good.

我的问题是,当我加入了 Horizo​​ntalScrollView ,我的列表中的项目变得不可点击。他们没有得到橙色背景点击时,他们不火 OnItemClickedListener 我已经设置了(做了一个简单的 Log.d 电话)。

My problem is that when I added the HorizontalScrollView, my list items became unclickable. They don't get the orange background when clicked and they don't fire the OnItemClickedListener I have set up (to do a simple Log.d call).

我怎样才能让我的列表中的项目可点击一次?

How can I make my list items clickable again?

编辑:设置安卓descendantFocusability =blocksDescendants在最上面的的LinearLayout 似乎工作。我想知道是否有其他的方法,虽然:?如果我想在我的列表中的项目可成为焦点的项目

setting android:descendantFocusability="blocksDescendants" on the topmost LinearLayout seems to work. I'd like to know if there are other ways, though: what if I want focusable items in my list items?

推荐答案

使用安卓descendantFocusability =blocksDescendants在最上面的的LinearLayout 的伎俩。里面的元素仍可以点击,他们只是没有作为焦点(即你不能按他们的非触摸屏设备上)。好足够了。

Using android:descendantFocusability="blocksDescendants" on the topmost LinearLayout did the trick. Elements inside can still be made "clickable", they're just not focusable (i.e. you can't click them on a non-touchscreen device). Good enough for me.

这篇关于ListView的项目无法点击与Horizo​​ntalScrollView内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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