【问题标题】:imeOptions isn't working in an AutoCompleteTextViewimeOptions 在 AutoCompleteTextView 中不起作用
【发布时间】:2015-05-25 23:27:49
【问题描述】:

我有麻烦。我正在使用 Google Maps Api v2,并创建了一个基本工具栏,就像在 Google Maps App 中一样。我上面有一个 AutoCompleteTextBox。

问题是当我按下 'DONE' 按钮(当屏幕处于纵向模式时)时,actionId==0KeyEvent= =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 22,使用我的 Moto G on Android Lollipop 并使用 Android Studio 1.1。 0.

【问题讨论】:

    标签: android events handle android-inputtype imeoptions


    【解决方案1】:

    是的,你是对的。因为您使用的是自己的文本“Buscar”而不是默认的“完成”。要克服您的问题,请更改 EditorAction 方法代码。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-16
      • 1970-01-01
      • 2019-11-27
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      相关资源
      最近更新 更多