Saturday, 17 August 2013

detect keystrokes in edittext

detect keystrokes in edittext

I have an edittext and a button. I want the button onclick handler to be
called when enter/carriage return is pressed on keyboard while in
edittext.
xml layout:
<EditText android:id="@+id/input"
android:layout_weight="1"
android:layout_width="0dp"
android:maxLength="1"
android:layout_height="wrap_content"
android:hint="@string/enter" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="handler"/>
handler looks like this:
public void handler(View view){
//handles buttonclick here
}
I have read other answers on Stack overflow, but none of the solutions are
working for me because probably I am doing something wrong. Can someone
tell me with code how to call handler when ENTER key is pressed in
edittext?

No comments:

Post a Comment