AutoCompleteTextView с параметрами времени поиска

Я хочу выполнить поиск двумя способами с помощью autocompletetextview. Первый — базовый, который использует ArrayAdapter (этот вариант работает нормально), второй использует IME_OPTION_SEARCH или actionSearch. Я хочу обсудить второй, который является проблемой здесь.

По сути, мне нужно добавить imeOptions в autocompletetextview с помощью «actionSearch», и это будет выглядеть так:

<AutoCompleteTextView
            android:layout_width = "0dp"
            android:layout_height = "wrap_content" android:id = "@+id/acPetShopSearch"
            app:layout_constraintStart_toEndOf = "@+id/ivPetShopSearchIcon" android:layout_marginStart = "8dp"
            app:layout_constraintTop_toTopOf = "parent"
            app:layout_constraintBottom_toBottomOf = "parent" android:backgroundTint = "@android:color/transparent"
            android:hint = "@string/pet_shop_search_hint"
            android:imeOptions = "actionSearch"
            android:inputType = "textAutoComplete|textAutoCorrect"
            app:layout_constraintEnd_toEndOf = "parent" android:layout_marginEnd = "16dp"
            android:textColorHint = "@color/pinkish_grey" android:textColor = "@color/purple_brown"
            android:textSize = "12sp" android:singleLine = "true"/>

Затем я устанавливаю прослушиватель редактора в представление, подобное простому EditText с actionSearch, так что это будет выглядеть так:

acPetShopSearch.setOnEditorActionListener(object : TextView.OnEditorActionListener {
        override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent): Boolean {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                doSearch(acPetShopSearch.text.toString())
                return true
            }
            return false
        }
    })

Я попробовал это, и я получил такую ​​​​ошибку:

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter event at id.paw.pawcolony.view.petshop.PetShopActivity$successCity$1.onEditorAction(Unknown Source:7) at android.widget.TextView.onEditorAction(TextView.java:6271) at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:138) at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:360) at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:85) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6806) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

Отличается ли поведение AutoCompleteTextView от EditText? Есть ли способ поместить функцию поиска в AutoCompleteTextView?

Я хочу выполнить поиск двумя способами. Во-первых, поиск можно выполнить, щелкнув элемент в AutoCompleteTextView. А во-вторых, я хочу искать именно по тому, что я печатаю, а не по адаптеру. Является ли это возможным? @pskink

Toshiro007 02.03.2019 07:05

@pskink, но это приложения для Android, не использующие jquery, поэтому, возможно, мы обсуждаем разные вещи.

Toshiro007 02.03.2019 07:50
2
2
565
1

Ответы 1

acPetShopSearch.setOnEditorActionListener(object : TextView.OnEditorActionListener {
        override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent?): Boolean {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                doSearch(acPetShopSearch.text.toString())
                return true
            }
            return false
        }
    })

Исправлен мой, сделав KeyEvent обнуляемым

Другие вопросы по теме