Have edittext show different keys than what was pressed

☆樱花仙子☆ 提交于 2019-12-11 22:58:49

问题


Im trying to have an edittext which would prompt a keyboard to pop-up when the user selects the edit text. When the user starts typing, it should fill the edittext with the keystrokes that the user puts in... but once a boolean value changes, then the keystrokes that get put will be different than what the user puts in.

If the boolean value is changed, then typing any key in the edittext updates will update, and lets say a "x" gets put in place instead of pressing "z".

The way that I can see about cracking this would be a lengthy keyUp() method that includes ALL keys and puts in their "x" when they get pressed if the boolean is true. Are there any methods or suggestions as to what I could do insead of the lengthy keyUp method. The keyup method doesn't work with

The boolean method that would change would start when a "." gets pressed in the edit test.


回答1:


Take a look at the TextWatcher class. It will allow you to intercept and manipulate user inputs as appropriate (depending on your boolean flag's value) as each character is entered. You can set a TextWatcher on an EditText using the addTextChangedListener method.



来源:https://stackoverflow.com/questions/27465024/have-edittext-show-different-keys-than-what-was-pressed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!