35

I have two AutocompleTextViews and I want to switch to the next if the user presses "NEXT", and make the virtual keyboard disappear when he hits "DONE" at the second AutocompleTextView. So far, the buttons "NEXT"/"DONE" do nothing at all.... Unfortunately I found no resources addressing this problem.

Any suggestions? thx

EDIT: Just want to add that this was asked when Android was on version 2.3 or something like that.

MJB
  • 3,934
  • 10
  • 48
  • 72
  • I am doing something similiar HERE!!! http://stackoverflow.com/questions/12854336/autocompletetextview-backed-by-cursorloader – Etienne Lawlor Oct 30 '12 at 19:48

4 Answers4

96

I ran into this problem and fixed it by setting the imeOptions on the AutocompleteTextView to actionNext.

Example:

<AutoCompleteTextView
    android:id="@+id/dialog_product_name"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:singleLine="true"
    android:completionThreshold="1"
    android:imeOptions="actionNext"
    />
cebru
  • 1,432
  • 15
  • 10
3

I found this solution for the "NEXT" problem: in your View source code write something like this

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
    if (firstAutoComplete.hasFocus()) {
    // sends focus to another field (user pressed "Next")
    otherText.requestFocus();
    return true;
    }
    else if (secondAutoComplete.hasFocus()) {
            // sends focus to another field (user pressed "Next")
    anotherText.requestFocus();
    return true;
    }
}
return false;
}

It seems to be an old Android http://code.google.com/p/android/issues/detail?id=4208. Here I found my solution: http://groups.google.com/group/android-developers/browse_thread/thread/e53e40bfe255ecaf.

Paolo
  • 100
  • 5
  • While this works when implementing your own view, you might also check out to add an OnKeyListener through setOnKeyListener and using more or less the same Code (override onKey(...)). I like cebru's answer more, as it uses the predefined way - though actionNext should be the default when a next button is displayed anyways. – icyerasor Mar 03 '12 at 00:19
0

Just add these two lines into AutoCompleteTextView xml Code:

            android:completionThreshold="1"
            android:imeOptions="actionNext"
Wajid khan
  • 842
  • 9
  • 18
0

Don't forget to add inputType="text" otherwise you'll have enter button instead of next/done one:

<AutoCompleteTextView
    android:id="@+id/suppliers"
    android:layout_width="@dimen/summary_input_width"
    android:layout_height="wrap_content"
    android:hint="@string/current_supplier"
    android:imeOptions="actionNext"
    android:inputType="text"
    android:lines="1" />
Honza Musil
  • 320
  • 2
  • 10