Android Row becomes Unclickable with Button

前端 未结 4 2050
时光取名叫无心
时光取名叫无心 2020-12-01 03:23

I have a listView, where each row has a button in the row layout. However, this seems to make the row itself unclickable. How can I make both the button and row clickable? <

4条回答
  •  盖世英雄少女心
    2020-12-01 03:50

    Whenever I see posts concerning the android:focusable and android:clickable attributes, I always see them being both set to the same value at once. I figured there must be a reason if they are two separate attributes instead of being one.

    It turns out that a much better way of achieving your desired behavior is to set

    android:focusable="false" 
    

    or

    yourButton.setFocusable(false)
    

    on the Button in your View. Once you do that, you'll be both able to set an OnClickListener on the Button, and a click on the row will fire the onListItemClick() method in your OnItemClickListener.

提交回复
热议问题