16

I have One AutocompleTextView and I want to make the virtual keyboard disappear when he hits "DONE" at the AutocompleTextView. So far, the buttons "NEXT"/"DONE" do nothing at all. Any ideas?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Pinki
  • 21,723
  • 16
  • 55
  • 88

5 Answers5

18

Add this Property to your AutoCompleteTextView in xml:

android:imeOptions="actionDone"
Bhavin Nattar
  • 3,189
  • 2
  • 22
  • 30
fasttrack
  • 181
  • 1
  • 4
12

The following works for all the Views which support imeOptions; for instance EditText, TextView, AutocompleteTextView, etc.

In your xml:

<autocompleteTextView

inputType = "text"
imeOptions = "actionDone"
/>

In Java:

autocomplete = (AutoCompleteTextView) issueDetailView.findViewById(R.id.yourId);
autocomplete.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
               if(actionId== EditorInfo.IME_ACTION_DONE) {
                  //do Whatever you Want to do
               }
                return true;
            }
        });
Rahul Jain
  • 121
  • 1
  • 4
  • 1
    problem with this is that i cannot get it to have more then one line of text, both `android:minLines` and `android:lines` dont work with this solution for me. – Kostyantin2216 Apr 14 '17 at 13:14
  • I'd like to point out that inputType = "text" is necessary for imeOption to work. I didn't have it and was seing the return button – jack_the_beast Mar 21 '22 at 15:13
8

Just add the following on yours XML layout file:

  android:imeOptions="actionDone"
  android:singleLine="true"
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Frank021
  • 121
  • 2
  • 11
  • I think this may be a bug in Android, something to do with backward compatibility or even maybe device specific. IME options won't work without single line (depreciated), even when max-lines is specified. – micwallace Oct 30 '16 at 13:05
  • What if we want multiline enable? – Kishan Solanki Apr 10 '18 at 05:59
  • by default autocompletetextview singleline property remains false that's why when just put android:imeOptions="actionDone" the soft keyboard doesn't work – Ayan Bhattacharjee May 12 '21 at 06:22
1

Check android:imeOptions attribute.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
alinux
  • 114
  • 2
1

In my case android:imeOptions only works if i set android:inputType which is

android:inputType="textAutoComplete" android:imeOptions="actionDone"

Sourav Anand
  • 41
  • 2
  • 3