2

問題があります。私は Google Maps Api v2 を使用しており、Google Maps アプリのような基本的なツールバーを作成しました。そこに AutoCompleteTextBox があります。

問題は、「DONE」ボタン(画面が縦向きモードの場合)、actionId==0およびKeyEvent==0を押したときですが、ラベル付きのアクションボタンを押したとき(画面が横向きモードの場合)です。動作しますが、DONEボタンが機能しません。

Java コードの実装では、次のように書きました。

autoCompleteTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                //Log.i("AutoCompleteTextView", "Evento onEditorAction ... ");
                search();
                handled = true;
            }
            Log.i("AutoCompleteTextView", "Evento onEditorAction ... " + actionId);
            return handled;
        }
    });

そして、私が使用したXMLレイアウトでは:

<AutoCompleteTextView
    android:id="@+id/autoText"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:layout_marginLeft="48dp"        
    android:layout_marginBottom="6dp"
    android:layout_marginRight="6dp"
    android:gravity="bottom"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/fontColorMenu"
    style="@style/AutoCompleteTextViewAppTheme"
    android:imeActionLabel="Buscar"
    android:imeOptions="actionDone"
    android:hint="Ingrese ciudad"
    android:inputType="text"/>

私はtargetSdkVersion 22Android Lollipop の Moto G 、およびAndroid Studio 1.1.0を使用しています。

4

1 に答える 1

2

はい、あなたは正しいです。デフォルトの「Done」ではなく、独自のテキスト「Buscar」を使用しているためです。問題を解決するには、EditorAction メソッド コードを変更します。

 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        boolean handled = false;
        if (actionId == event.ACTION_DOWN) {
              search();
              handled = true;
        }
        return handled;

 }
于 2015-07-16T03:04:03.313 に答える