android学习之EditText需要点击两次触发onclick问题解决

时间:2020-12-13 19:33:22

Unlike most other controls, EditTexts are focusable while the system is in ‘touch mode’. The first click event focuses the control, while the second click event actually fires the OnClickListener. If you disable touch-mode focus with the android:focusableInTouchMode View attribute, the OnClickListener should fire as expected.

<EditText 
    android:text="@+id/EditText01"
    android:id="@+id/EditText01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusableInTouchMode="false" />