Reputation: 687
I set an Ok key on soft android keyboard when i click on the edittext shown below:
<EditText
android:id="@+id/rlMP3SeekContainer"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@drawable/text_rougea"
android:singleLine="true"
android:imeOptions="actionDone"
android:ems="10"
android:hint="@string/hint_deezer_search"
android:paddingLeft="@dimen/eight_dp"
android:paddingRight="@dimen/eight_dp"
android:textColor="@color/black"
android:textColorHint="@color/gray_text"
android:textSize="@dimen/twelve_sp" />
When the keyboard appear i want the user when clicking on the ok button do something. but how can i override the ok button on the keyboard to do whatever i want
Upvotes: 7
Views: 4574
Reputation: 5407
You need to implement the OnEditorActionListener:
yourEditText.setOnEditorActionListener(
new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
/* your code here */
}
}
});
Upvotes: 21