My problem: I'm using an AutoCompleteTextView
list of options for the user and despite having the activity xml setup with android:imeOptions="actionDone"
the keyboard still provides a return option instead presenting the keyboard with the "Done" option.
What I have tried: I searched a few posts but could not find one with this specific issue. So I tried the following solution posted from another post applicable for EditText
, so I could apply this "Done" action to multiple AutoCompleteTextViews within the same activity (posted here).
Again, the issue is that despite the XML AutoCompleteTextView
is setup for actionDone
the keyboard shows the return arrow.
XML
<AutoCompleteTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/viewSource"
android:hint="@string/hint_source"
android:imeOptions="actionDone"
android:padding="5dp"
android:background="@color/colorWhite"
app:layout_constraintStart_toEndOf="@id/lblViewSource"
android:layout_marginStart="5dp"
app:layout_constraintEnd_toEndOf="parent"
android:textSize="12sp"
android:layout_marginEnd="5dp"
app:layout_constraintBaseline_toBaselineOf="@+id/lblViewSource"/>
The AutoCompleteTextView calling code
sourceTitle.setOnEditorActionListener(new DoneOnEditorActionListener());
Custom Class Code for managing "Done" and keyboard close
class DoneOnEditorActionListener implements AutoCompleteTextView.OnEditorActionListener {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
}
The following ended up solving my problem. Once I added and defined the inputType
in the activity XML the done button appeared. So, it appears that the inputType
needs defined with the imeOptions
or the done button will not appear. This was one of the suggestions from the following link though none of answers were approved.
Done is not working in softKeyboard in Autocomplete TextView in android
android:inputType="text"
android:imeOptions="actionDone"