用户单击我的EditText后如何做 [英] How to do something after user clicks on my EditText
问题描述
我有一个显示时间的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
视图"属性禁用了触摸模式焦点,则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后如何做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!