問題描述
我有一個顯示時間的 EditText
.用戶單擊 EditText
后,我想顯示一個 TimePickerDialog
,因此我將 View.OnClickListener
設置為我的 EditText
.
I have an EditText
that shows time. After user clicks the EditText
I want to show a TimePickerDialog
, so I set a View.OnClickListener
to my EditText
.
但是 OnClickListener
的行為很奇怪 - 我觸摸 EditText
然后出現軟件鍵盤(我不想要).當我再次觸摸時, OnClickListener.onClick()
終于被調用并出現對話框.
But the OnClickListener
is behaving weirdly - I touch the EditText
and then software keyboard appears (which I don't want). When I touch again, OnClickListener.onClick()
is finally called and the dialog appears.
如果我想讓對話框立即出現怎么辦?
What should I do if I want the dialog to appear immediately?
推薦答案
與大多數其他控件不同,EditText
在系統處于觸摸模式"時是可聚焦的.第一個單擊事件聚焦控件,而第二個單擊事件實際上觸發 OnClickListener
.如果您使用 android:focusableInTouchMode
View 屬性禁用觸摸模式焦點,則 OnClickListener
應該會按預期觸發.
Unlike most other controls, EditText
s 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" />
這篇關于用戶點擊我的 EditText 后如何做某事的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!