我有一个 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模板网!