I have to click the button twice for it to work

前端 未结 8 1826
温柔的废话
温柔的废话 2020-12-05 04:33

So I have a button in my app and an edittext. When I click the button and write something in the edittext, a textview changes. It all works as it should except for one thing

8条回答
  •  一向
    一向 (楼主)
    2020-12-05 05:03

    My problem was the Button XML defining:

    android:focusableInTouchMode="true"
    

    Remove this attribute and the button doesn't require being touched twice. It appears as though the first touch is consumed to assign focus on the button and the second then triggers the OnClickListener.

    Note that the Button works without issue with the android:focusable="true" attribute.

提交回复
热议问题