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?
Try using this android:lines="1"
in your layout xml for EditText.
This will consider the Enter Key as new line and focus will not loose. Although existing text might not be visible due to only one line, as it moved upword and get hidden.