My activity implements KeyListener and my edittext has a key listener set.
editor = new EditText(this);
editor.setMinLines(4);
editor.setMinimumWidth(400);
editor.setKeyListener(this);
WHen the user types something and presses “enter” on the softkeyboard a textview’s text is set to the users input.
@Override
public int getInputType() {
return InputType.TYPE_TEXT_FLAG_MULTI_LINE;
}
@Override
public boolean onKeyDown(View view, Editable text, int keyCode,
KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_ENTER){
outview.setText(editor.getText());
}
return true;
}
Here outview is a TextView. My problem is that in this activity the physical back button doesn’t work. Press it and nothing happens. ANy advice would be welcomed.
By returning
truefrom theonKeyDownfunction, you are informing Android that you have handled all key events. Instead, only return true in the case of the enter key. Returnfalseotherwise. This will allow Android to handle the back button key press.