开发者

AutocompleteTextView: on "NEXT" highlight next TextView, on "DONE", make keyboard disappear

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 li开发者_如何学编程ke that.


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"
    />


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.


Just add these two lines into AutoCompleteTextView xml Code:

            android:completionThreshold="1"
            android:imeOptions="actionNext"


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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜