AutoComplete ShowDropdown不显示下拉菜单(但在其他情况下)

时间:2019-04-26 15:19:40

标签: android kotlin kotlin-android-extensions

我有四个autoCompleteTextViews设置,以在他们获得焦点时显示一个下拉菜单(使用它更像是一个可选的下拉菜单,而不是等待用户首先输入数据)。在活动开始时,我将从存储中提取下拉列表的数据,并且成功接收了所有4个数组。在活动中的其他三个实例中,它的工作原理就像是一种魅力。但是,由于某些原因,这些字段之一从未显示下拉列表。有问题的一个标题为下面的“ loaderAutoCompleteTextView”:

//Setup autoCompleteTextView list with drivers
    val driverAdapter = ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, driverArrayList)
    driverAutoCompleteTextView.setAdapter(driverAdapter)

    //show AutoComplete information without having to type first.
    driverAutoCompleteTextView.onFocusChangeListener = View.OnFocusChangeListener { /*view*/_, hasFocus ->
        if (hasFocus) {
            driverAutoCompleteTextView.showDropDown()
            Log.d("BEAU", "DRIVER DROPDOWN SHOULD BE HERE!")
        } else {
            driverAutoCompleteTextView.dismissDropDown()
        }
    }

    //Setup autoCompleteTextView list with loaders
    val loaderAdapter = ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, loaderArrayList)
    loaderAutoCompleteTextView.setAdapter(loaderAdapter)

    //show AutoComplete information without having to type first.
    loaderAutoCompleteTextView.onFocusChangeListener = View.OnFocusChangeListener { /*view*/_, hasFocus ->
        if (hasFocus) {
            loaderAutoCompleteTextView.showDropDown()
            Log.d("BEAU", "LOADER DROPDOWN SHOULD BE HERE!")
        } else {
            loaderAutoCompleteTextView.dismissDropDown()
        }
    }

这是它们各自的XML:

<AutoCompleteTextView
    android:id="@+id/driverAutoComplete"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginEnd="5dp"
    android:layout_marginRight="5dp"
    android:hint="@string/driver_name"
    android:inputType="textCapWords"
    android:imeOptions="actionNext"
    app:layout_constraintBottom_toBottomOf="@+id/driverView"
    app:layout_constraintEnd_toEndOf="@+id/driverView"
    app:layout_constraintStart_toStartOf="@+id/verticalGuidelineEditLoad50percent"
    app:layout_constraintTop_toTopOf="@+id/driverView" />

<AutoCompleteTextView
    android:id="@+id/loaderAutoComplete"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginEnd="5dp"
    android:layout_marginRight="5dp"
    android:hint="@string/loader_name"
    android:inputType="textCapWords"
    android:imeOptions="actionDone"
    app:layout_constraintBottom_toBottomOf="@+id/loaderView"
    app:layout_constraintEnd_toEndOf="@+id/loaderView"
    app:layout_constraintStart_toStartOf="@+id/verticalGuidelineEditLoad50percent"
    app:layout_constraintTop_toTopOf="@+id/loaderView" />

我什么都看不见,但logcat有所不同。每当我将焦点放在loaderAutoCompleteTextView上时,都会出现此错误:

W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.

我认为这可能是因为它试图消除从未创建的下拉菜单吗?任何帮助将不胜感激。

0 个答案:

没有答案