Setting EditText to single line makes it lose its focus after pressing enter

Viewed 1503

I use an EditText in my code and compare its content to a string when clicking on a button. Unfortunately doing this with the enter key through onKey causes problems because enter creates a line break. I used:

setSingleLine(true);

to prevent this. But now pressing enter leads to the EditText losing its focus. Why does it behave like this and how do I fix it?

2 Answers
Related