【问题标题】:Use NumberPicker as Input Method instead of standard keyboard使用 NumberPicker 作为输入法而不是标准键盘
【发布时间】:2018-01-06 14:29:28
【问题描述】:

我的活动中有几个 EditText 字段。对于其中一个字段,我喜欢使用 NumberPicker 输入值(例如年龄、身高或其他)。单击特定的 editText 后,是否有可能显示 NumberPicker 而不是键盘? 我知道您可以在布局文件中将 inputType 更改为“text”、“numberPassword”等,但我还没有找到将 inputType 设为 customView 的可能性。

【问题讨论】:

标签: java android input android-edittext


【解决方案1】:

您可以将编辑文本的输入类型设置为“无”并将可聚焦设置为 false。

            <EditText
                android:inputType="none"
                android:id="@+id/editText"
                android:focusable="false"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

在你的java文件中,你可以在你的编辑文本中设置一个onClickListener,你可以在对话框或其他东西中显示NumberpickerView,然后在编辑文本中设置值。要将数字选择器显示为对话框,您可以参考问题评论中的 stackoverflow 链接。

【讨论】:

  • 这就是我最终想出的解决方法。但是由于我使用了几个编辑文本——一些使用键盘,一些选择器——如果输入视图在同一个地方,那将是更好的用户体验。
猜你喜欢
  • 1970-01-01
  • 2013-09-18
  • 1970-01-01
  • 2015-03-28
  • 2017-12-21
  • 1970-01-01
  • 2013-09-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多