I am trying to make a way for a user to enter text in a TextView from an EditText. However, if the user enters something and wants to fix it, I want them to be able to press the space bar on an empty EditText to get the last thing they wrote. The first problem is that if they type βhelloβ, press enter to add it to the TextView (which will clear it from EditText), and then press the space bar and EditText βhelloβ. Not what I want, and I cannot understand why.
My code to put the entered text on a hold line:
b1 = ti.getText().toString();
Then, if the user presses the space bar, I believe that they should get b1 in the EditText. Instead, I get: " " + b1 . Why is this added space?
if((event.getAction()==KeyEvent.ACTION_DOWN)&&(key == KeyEvent.KEYCODE_SPACE)){ if(ti.getText().toString().equals("")){ ti.setText(b1); }
My second, big problem is that the above code only works on a hardware keyboard. What is the key event for pressing the soft keyboard?
This is all onKeyListener.
source share