EditText:如何启用/禁用输入?

EditText: how to enable/disable input?(EditText:如何启用/禁用输入?)
本文介绍了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:如何启用/禁用输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)
How can i use MYSQL database connection in iphone application useing cocos2d?(如何在使用 cocos2d 的 iphone 应用程序中使用 MYSQL 数据库连接?)
Smoothly drag a Sprite in cocos2d - iPhone(在 cocos2d 中平滑拖动一个 Sprite - iPhone)
Cocos2D complex animations(Cocos2D 复杂动画)