[英]Unable to NotifyDataSetChanged on a RecyclerView when EditText is in Focus
我有一个名为MainFragment的片段的 Activity,它有一个ViewPager2来显示一些片段。 其中之一是SearchFragment 。 SearchFragment有一个带有 TextWatcher 的EditText ,在文本更改时,正在调用 API 来获取建议。 当我将这些建议设置为显示在EditText正下方的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"
,它有一个错误,如果 EditText 处于焦点状态,则会导致视图元素失去焦点。
更新为"androidx.viewpager2:viewpager2:1.0.0-rc01"
,问题现已解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.