35

我有两个AutocompleTextViews,如果用户按下“NEXT”,我想切换到下一个,并在他在第二个 AutocompleTextView 上点击“DONE”时使虚拟键盘消失。到目前为止,按钮“NEXT”/“DONE”什么也没做……不幸的是,我没有找到解决这个问题的资源。

有什么建议么?谢谢

编辑:只想补充一点,当 Android 版本为 2.3 或类似版本时,有人问过这个问题。

4

4 回答 4

96

我遇到了这个问题,并通过将 AutocompleteTextView 上的 imeOptions 设置为 actionNext 来解决它。

例子:

<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"
    />
于 2011-12-17T21:41:30.317 回答
3

我为“NEXT”问题找到了这个解决方案:在你的查看源代码中写这样的东西

@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;
}

这似乎是一个旧的 Android http://code.google.com/p/android/issues/detail?id=4208。在这里我找到了我的解决方案:http ://groups.google.com/group/android-developers/browse_thread/thread/e53e40bfe255ecaf 。

于 2011-05-09T16:45:50.957 回答
0

只需将这两行添加到 AutoCompleteTextView xml 代码中:

            android:completionThreshold="1"
            android:imeOptions="actionNext"
于 2018-01-15T08:49:05.777 回答
0

不要忘记添加 inputType="text" 否则你将有输入按钮而不是下一个/完成一个:

<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" />
于 2018-02-21T05:14:10.503 回答