1

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.

longkai
  • 3,598
  • 3
  • 22
  • 24
  • set the property focusable and focusableOnTouch mode property and clickable porperty to false in the textview xml – Rat-a-tat-a-tat Ratatouille Feb 20 '14 at 06:41
  • @Rat-a-tat-a-tatRatatouille I set them all false, but when I click the textview, the list' s ``onListItemClick`` is still not called. – longkai Feb 20 '14 at 09:20
  • set the linear layout to non-clickable also, and set them in the code also, that is, in the getView method set the properties to false via code also – Rat-a-tat-a-tat Ratatouille Feb 20 '14 at 09:24
  • @Rat-a-tat-a-tatRatatouille sorry for my inexperince. I didn' t mention **The textview use Linkify to provide some links**. I searched the web just now and commentted the Linkify code, it works... However, the links must be kept. any ideas? – longkai Feb 20 '14 at 09:44
  • if you really need the links then in that case, the onClick is the way to go for the links , where by when the link is clicked on, open the url in the webview. (do this in the getView method) – Rat-a-tat-a-tat Ratatouille Feb 20 '14 at 09:52
  • @Rat-a-tat-a-tatRatatouille Thanks, I find a sulution [here](http://stackoverflow.com/questions/7236840/android-textview-linkify-intercepts-with-parent-view-gestures/7327332#7327332) . plus, 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. – longkai Feb 20 '14 at 10:20
  • Yes possible, just the way you have written the rows selector, when you click the textview you can have its own selector too and place it in the textColor of the textview. like android:textColor="@drawable/demo_selector" – Rat-a-tat-a-tat Ratatouille Feb 20 '14 at 10:56

1 Answers1

5

After spenting some time trying, I solved both.

  1. the first. if your customized listview' s layout has a textview which has been set autolink or Linkify in the code, the click event in the textview won' t affect the list' s row. You have to extends your own TextView and override onTouchEvent method. please see it here

  2. 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:-)

Community
  • 1
  • 1
longkai
  • 3,598
  • 3
  • 22
  • 24