问题描述
我有一个 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:如何启用/禁用输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)