I want to add text in textview in android, but when the backspace is pressed the last character should be removed.
- I am using softkeyboard.
- I am creating textview dynamically.
- and update textview when key of soft-keyboard is dispatched/pressed.
This is my code:
@Override
public boolean dispatchKeyEvent(KeyEvent KEvent){
keyaction = KEvent.getAction();
if(keyaction == KeyEvent.ACTION_DOWN){
keycode = KEvent.getKeyCode();
keyunicode = KEvent.getUnicodeChar(KEvent.getMetaState() );
character = (char) keyunicode;
textView.setText(""+character);
}
return super.dispatchKeyEvent(KEvent);
}
Every time I press a key, textview is set with a new character and previous one gets overridden. Also if backspace is pressed than last character appended get deleted
Is there any way to do this to textview?