在列表视图的列一个TextView不能单击设置后descendantFocusability =" blocksDescendants" [英] a textview in a listview' s row cannot click after setting descendantFocusability="blocksDescendants"
问题描述
我写了一个自定义项目布局一个列表视图。布局有许多部件,有些会有自己的clicklistener。
I write a customized item layout for a listview. The layout has many widgets and some will have its own clicklistener.
当我点击该行,有时列表视图的onListItemClick工作,但有时并非如此。
When I click the row, sometimes the listview' s onListItemClick work, but sometimes not.
在我花了一些时间来寻找,我找到一种方法,设置机器人:descendantFocusability =blocksDescendants在布局的根。它的工作原理,但只有一个TextView中不能工作,(可点击的,fucusable ATTR曾经尝试过)。在列表中的适配器,我设置的TextView的onClickListener,它的工作原理。但是,这不是自然,没有人知道如何解决呢?
After I spent some time searching, I find a way, setting android:descendantFocusability="blocksDescendants" in the layout' s root. It works, but only one textview cannot work,(the clickable, fucusable attr have been tried). In the list' s adapter, I set the textview' s onClickListener, it works. But that' s not nature, does anyone know how to solve it?
顺便说一句,有没有办法来区分diffderent插件点击?现在,不管我点击(除了的TextView),整行的背景选择得到了改变。
btw, is there a way to distinguish diffderent widget' click? Now, no matter what I click(except that textview), the whole row' s background selector got changed.
非常感谢!
//我的列表行布局根
// my list row layout root
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:descendantFocusability="blocksDescendants"
android:padding="@dimen/medium"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
//可怕的TextView
// the awful textview
<TextView
android:id="@+id/text"
android:textColor="@android:color/secondary_text_light"
android:textColorLink="@android:color/holo_blue_dark"
android:layout_marginTop="@dimen/small"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:layout_below="@id/nick"
android:layout_alignLeft="@id/nick"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
更新
update
TextView的使用Linkify提供一些链接的功能。
the textview uses Linkify to provide some links functionalities.
推荐答案
spenting一段时间尝试后,我解决了这两个。
After spenting some time trying, I solved both.
-
第一。如果您的自定义列表视图的布局具有已设置
自动链接
或Linkify
在code一个TextView,在TextView中的单击事件赢得了'吨影响列表的列。你必须为扩展您自己的的TextView
和覆盖的onTouchEvent
方法。请看看它<一个href="http://stackoverflow.com/questions/7236840/android-textview-linkify-intercepts-with-parent-view-gestures/7327332#7327332">here
the first. if your customized listview' s layout has a textview which has been set
autolink
orLinkify
in the code, the click event in the textview won' t affect the list' s row. You have to extends your ownTextView
and overrideonTouchEvent
method. please see it here
第二。刚刚成立的自定义列表视图的根节点:安卓descendantFocusability =blocksDescendants
,然后在你的小工具,这将有自己的 onClickListener
,设置机器人:可点击=真正的
,它为我工作。
the second. just set in the customized listview' s root node: android:descendantFocusability="blocksDescendants"
, and then, in your widget which will have its own onClickListener
, set android:clickable="true"
, it works for me.
希望你遇到同样有用的那些: - )
hope it useful for those you encounter the same:-)
这篇关于在列表视图的列一个TextView不能单击设置后descendantFocusability =&QUOT; blocksDescendants&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!