I need a way to take text from a “EditText” as soon as the user presses “Enter” and it should also call a method if it loses focus.
I created EditText like this:
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button2"
android:ems="10" >
To receive key presses your EditText needs to have focus:
then set the onkeylistener():
For focus lost, you need to implement the
View.onFocusChangeinterface and check thathasFocusisfalse