用户点击我的 EditText 后如何做某事

How to do something after user clicks on my EditText(用户点击我的 EditText 后如何做某事)
本文介绍了用户点击我的 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 View 属性禁用触摸模式焦点,则 OnClickListener 应该会按预期触发.

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" />

这篇关于用户点击我的 EditText 后如何做某事的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)