Answer the question
In order to leave comments, you need to log in
Why is input button click not handled in EditText?
When typing text in an EditText, after pressing the enter button, it wraps to another line, although this is not at all necessary. How can text input be handled? When orienting Landscape, the Next button appears and the processing of its click is triggered.
The code itself:
tv = (TextView) findViewById(R.id.textView);
editText = (EditText) findViewById(R.id.editText);
editText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
tv.setText(editText.getText().toString());
return true;
}
return false;
});
Answer the question
In order to leave comments, you need to log in
I came to this solution:
EditText has android:imeOptions="actionNext"
And then the following handler code:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
tv.setText(editText.getText().toString());
return true;
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question