Android 当EditText处于焦点时,无法在RecyclerView上通知DataSetChanged

Android 当EditText处于焦点时,无法在RecyclerView上通知DataSetChanged,android,android-fragments,android-recyclerview,android-edittext,android-nested-fragment,Android,Android Fragments,Android Recyclerview,Android Edittext,Android Nested Fragment,我有一个名为MainFragment的片段的活动,它有一个ViewPager2来显示一些片段。其中之一是SearchFragmentSearchFragment有一个带有TextWatcher的EditText,在文本更改时,将调用API来获取建议。当我将这些建议设置为RecyclerView(显示在编辑文本的正下方)时,它不会得到更新,除非我触摸RecyclerView 我试着运行一个处理程序来进行API调用并更新RecyclerView,而不让EditText获得焦点,结果成功了。当Edit

我有一个名为MainFragment的片段的活动,它有一个ViewPager2来显示一些片段。其中之一是SearchFragmentSearchFragment有一个带有TextWatcher的EditText,在文本更改时,将调用API来获取建议。当我将这些建议设置为RecyclerView(显示在编辑文本的正下方)时,它不会得到更新,除非我触摸RecyclerView

我试着运行一个处理程序来进行API调用并更新RecyclerView,而不让EditText获得焦点,结果成功了。当EditText未聚焦时,RecyclerView会很好地更新数据

<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>


ViewPager2库出现问题

我使用的是
“androidx.viewpager2:viewpager2:1.0.0-beta05”
,它有一个Bug,如果EditText处于焦点位置,会导致视图元素失去焦点


更新为“androidx.viewpager2:viewpager2:1.0.0-rc01”,问题现已解决。

您能分享更多详细信息吗?(片段和适配器类)在API结果之后是否调用notifyDataSetChanged?恐怕我不能这样做。我将制作一个虚拟项目并与大家分享。谢谢您的回复@HamzaKhan。现在问题解决了。ViewPager2库中有一个bug,已更新,现在正在运行。