Skip to content

[Exposed Dropdown Menu] Scroll always to top instead of selected item #1600

@EliuTimana

Description

@EliuTimana

Description: I've implemented an exposed dropdown menu following the material docs material.io and this everything is working fine, but every time I want to select another item that is at the end of the list I have to scroll down, again and again, that's not the normal behavior of the Spinner widget, ¿is that possible?

Expected behavior: Vertical scroll should be set to the selected item, this can improve accessibility when the list contains a lot of elements.
img
Source code:

...
<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_marginStart="16dp"
   android:layout_marginTop="8dp"
   android:layout_marginEnd="16dp"
   android:orientation="vertical"
   tools:context=".ui.filter.FilterFragment">
   <com.google.android.material.textfield.TextInputLayout
      android:id="@+id/dropdown_department"
      style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="@string/department"
      app:data="@{viewModel.departments}">
      <AutoCompleteTextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:inputType="none"
         android:overScrollMode="always" />
   </com.google.android.material.textfield.TextInputLayout>
   <Spinner
      android:id="@+id/spinner_province"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="8dp"
      app:data="@{viewModel.departments}"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/textViewProvince" />
</LinearLayout>
...
val adapterProv = SpinnerUbigeoAdapter(requireContext(), OnItemSelected {
    viewModel.onSelectProvincia(it)
})
(binding.dropdownProvince.editText as? AutoCompleteTextView)?.setAdapter(adapterProv)
binding.spinnerProvince.adapter = adapterDep

Android API version: 29

Material Library version: 1.2.0

Device: Emulator or real device

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions