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 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?
Instead of touch Listener use Text Change Listener:
If I understand correctly you just need something like
not editable and clickable. Set the
OnClickListener
and you're done. In theory, in the practice you should add toowhich is deprecated but does the trick.
I solved this by using a customized Button like this:
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 theOnClickListener
. If you disable touch-mode focus with theandroid:focusableInTouchMode
View attribute, theOnClickListener
should fire as expected.It sounds like you don't want the user to actually be able to type in the EditText. You just want them to be able to pick a time via a time picker. So why not just a button that pops up a TimePickerDialog? You could display the time that was picked in a TextView.
Or you could just replace the EditText view with a TimePicker view (not a dialog, just a regular view).
Another solution is to use the
ontouchlistener
:If it returns
true
the event is handled and keyboard wont popup. If you'd want the keyboard to still popup and register click you'd have it returnfalse
.