Android的:如何做好用户点击后的东西在我的EditText [英] Android: How to do something after user clicks on my EditText
问题描述
我有一个EditText,显示时间。用户点击的EditText后,我想显示TimePickerDialog,所以我设置一个View.OnClickListener我的EditText。但OnClickListener的行为wierdly - 我接触的EditText,然后软键盘出现(这我不希望)。当我再次触碰,OnClickListener.onClick()终于打来电话,显示的对话框。
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. But the OnClickListener is behaving wierdly - 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
。如果禁用触控模式下的对焦与机器人: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" />
这篇关于Android的:如何做好用户点击后的东西在我的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!