Have edittext show different keys than what was pr

2019-09-07 23:37发布

问题:

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.