Невозможно NotifyDataSetChanged для RecyclerView, когда EditText находится в фокусе - PullRequest
1 голос
/ 11 ноября 2019

У меня есть действие с фрагментом, называемым MainFragment , в котором есть ViewPager2 для отображения нескольких фрагментов. Одним из которых является SearchFragment . SearchFragment имеет EditText с TextWatcher, при изменении текста выполняется вызов API для извлечения предложений. Когда я устанавливаю эти предложения для RecyclerView , который показан прямо под EditText , он не будет обновляться, пока я не коснусь RecyclerView .

Я попытался запустить обработчик для вызова API и обновления RecyclerView , не позволяя EditText получить фокус, и это сработало. RecyclerView обновляет данные очень хорошо, когда EditText не сфокусирован.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/search_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/almostBlack"
    tools:context=".presentation.ui.modules.search.view.SearchFragment">

    <com.vishal.presentation.ui.common.custom.ClearableAutoCompleteTextView
        android:id="@+id/etSearchText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/transparent"
        android:ellipsize="end"
        android:focusable="true"
        android:fontFamily="@font/sfprotext_regular"
        android:gravity="center|start"
        android:hint="@string/search_hint"
        android:imeOptions="actionSearch"
        android:inputType="text"
        android:maxLength="50"
        android:maxLines="1"
        android:padding="12dp"
        android:singleLine="true"
        android:textColor="@color/white"
        android:textColorHint="@color/veryLightPink"
        android:textSize="16sp"
        app:clearIconDrawWhenFocused="true"
        app:clearIconDrawable="@drawable/ic_close_white_24dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/autoCompleteSuggestions"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/almostBlack"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/etSearchText" />

</androidx.constraintlayout.widget.ConstraintLayout>

1 Ответ

1 голос
/ 12 ноября 2019

Возникла проблема с библиотекой ViewPager2.

Я использовал "androidx.viewpager2:viewpager2:1.0.0-beta05", в котором была ошибка, из-за которой элементы представления теряли фокус, если EditText находится в фокусе.

Обновлено до "androidx.viewpager2:viewpager2:1.0.0-rc01" и проблема решена.

...