Home  >  Q&A  >  body text

android-studio - Why android:clickable="true" cannot trigger click events in the item layout of RecyclerView?

Why can't android:clickable="true" trigger a click event in the item layout of RecyclerView?
The original code is like this:

<TextView
        android:id="@+id/city_name"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:background="?android:attr/selectableItemBackground"
        android:clickable="true"
        android:gravity="center_vertical"
        android:padding="16dp"
        android:text=" 新都市 "
        android:textColor="#666666"
        android:textSize="14sp"/>

I found that when clicking, there was only a ripple effect but the click event could not be triggered. Later, I changed android:clickable="true" to false, and the rest remained unchanged, but there was a ripple effect and a click event. Why is this?

曾经蜡笔没有小新曾经蜡笔没有小新2712 days ago1033

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-06-06 09:54:55

    What event do you want? Whose response is your incident? TextView click, or RecyclerView Item click? These are two concepts.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-06 09:54:55

    If you bind the click event to the item, when the clickable of TextView is true, it will consume the entire event sequence and cannot trigger the click callback of the item

    reply
    0
  • Cancelreply