EditText: how to enable/disable input?(EditText:如何启用/禁用输入?)
问题描述
我有一个 7x6 网格的 EditText 视图.我希望在应用程序启动时将它们全部禁用,即它们的行为应该像普通的 TextViews 并且不可编辑.然后用户点击网格中的一个单元格,它会更改其背景并执行一些视觉操作.如果用户再次单击单元格,它应该允许编辑.我正在努力使用 OnClick() 和 OnFocusChange() 监听器,但我无法完成这样的基本交互.
I have a 7x6 grid of EditText views. I want all of them disabled when the application starts, ie they should behave like normal TextViews and not to be editable. Then the user taps one cell in the grid, it changes its background and performs something visual. If the user clicks on the cell one more time it should allow editing. I'm struggling with OnClick() and OnFocusChange() listeners, but I can't accomplish such a basic interaction.
使用 setEnabled() 和 setFocusable() 没有帮助.我想知道为什么即使像这样简单的任务在 Android 上也变得如此困难
Playing with setEnabled() and setFocusable() doesn't help. I wonder why even a simple task like this has been made so difficult on Android
推荐答案
我终于找到了解决方案.这是一个调用的问题
I finally found a solution. It's a matter of calling
setFocusableInTouchMode(boolean)setFocusable(boolean)
当 EditText 第一次创建时,它可以拦截点击.然后可以再次设置这些标志以使 EditText 可编辑,请求焦点,并使用 InputMethodManager 方法手动显示/隐藏软键盘
when the EditText is first created, so it can intercept the clicks. Then one can set those flags back again to make the EditText editable, request the focus, and manually show/hide the soft keyboard with InputMethodManager methods
这篇关于EditText:如何启用/禁用输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EditText:如何启用/禁用输入?
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
