Edit Text key listener(编辑文本键侦听器)
问题描述
我的布局中有一个 edittext 和一个按钮,在我的代码中我将 edittext 的 keyListener 设置为 null
I have an edittext and a button in my layout and in my code I'm setting keyListener of the edittext as null
editText.setKeyListener(null);
这样我就无法输入我的 edittext.现在点击我的按钮,我应该能够输入我的 ediitext.我怎样才能做到这一点.这是一个简单的问题,但我找不到任何解决方案.任何帮助将不胜感激.
so that I cannot type into my edittext. Now on my button click I should be able to type into my ediitext. How can I do that. It's a simple problem, but I'm not able to find any solution. Any help would be much appreciated.
推荐答案
我现在可能迟到了,但是我就是这样做的:
I'm probably late now but, this is the way I do it:
public class MyActivity extends Activity
{
private KeyListener listener;
private EditText editText;
public void onCreate(...)
{
editText = ... // Get EditText from somewhere
listener = editText.getKeyListener(); // Save the default KeyListener!!!
editText.setKeyListener(null); // Disable input
}
// When you click your button, restore the default KeyListener
public void buttonClickHandler(...)
{
editText.setKeyListener(listener);
}
}
基本上,在调用 setKeyListener(null) 之前,首先保存 EditText 的默认 KeyListener.然后,当您单击按钮时,再次调用 setKeyListener,传递您之前保存的默认侦听器.
Basically, you first save the EditText's default KeyListener before you call setKeyListener(null). Then, when you click your button, you call setKeyListener again, passing the default listener you previously saved.
这篇关于编辑文本键侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:编辑文本键侦听器
基础教程推荐
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
