[Android 問題] How to Add a Button in ListView, and Make the Event of onClick and onItemClick Coexist?

久未见 提交于 2020-01-02 07:53:45

If you add a Button on the view of each item in ListView,

the touch event is catched and reacted by the button instead of the ListView even outside the area of the Button.

The item can not be selected and switched.

It's a simplest solution that you can set the attribute android:focusable to be false to fix it as showed below:

<Button
     android:id="@+id/contact_list_item_hd_button"
  android:layout_width="30px"
     android:layout_height="30px"
     android:layout_gravity="center_vertical"
     android:layout_marginRight="10px"
     android:background="@drawable/contactlist_hd_button"
     android:textSize="8sp"
     android:focusable="false"
     android:visibility="invisible"
     />

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!