问题
I write a customized item layout for a listview. The layout has many widgets and some will have its own clicklistener.
When I click the row, sometimes the listview' s onListItemClick work, but sometimes not.
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?
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.
many thanks!
// 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">
// 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
the textview uses Linkify to provide some links functionalities.
回答1:
After spenting some time trying, I solved both.
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 herethe second. just set in the customized listview' s root node:
android:descendantFocusability="blocksDescendants"
, and then, in your widget which will have its ownonClickListener
, setandroid:clickable="true"
, it works for me.
hope it useful for those you encounter the same:-)
来源:https://stackoverflow.com/questions/21891008/a-textview-in-a-listview-s-row-cannot-click-after-setting-descendantfocusabilit