的EditText:如何启用/禁用输入? [英] EditText: how to enable/disable input?

查看:115
本文介绍了的EditText:如何启用/禁用输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有意见的EditText一个7x6网格。我希望所有的人都禁用应用程序启动时,即他们的行为应该像普通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(布尔)
  • setFocusable(布尔)

时,首先创建的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:如何启用/禁用输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆