androidkotlinandroid-recyclerviewandroid-edittextlistadapter

Force Edit text to remove focus after submitting list in recyclerview


I have a recycler view which have multiple edit text. On adding items to recyclerview, focus always shift towards the first editText of screen. I have already used android:focusable="true" and android:focusableInTouchMode="true" with parent layout of edit text. Below is my XML Code for the fragment:

 <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/layoutPickupLocation"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent">

                    <ImageView
                        android:id="@+id/iv_origin"
                        android:layout_width="15dp"
                        android:layout_height="15dp"
                        android:layout_marginStart="8dp"
                        android:src="@drawable/ic_origin_icon"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toStartOf="@+id/et_origin"
                        app:layout_constraintHorizontal_bias="0.0"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <EditText
                        android:id="@+id/et_origin"
                        style="@style/textGreyLight"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="6dp"
                        android:layout_marginEnd="@dimen/sixteen_dp"
                        android:background="@null"
                        android:imeOptions="actionDone"
                        tools:hint="Enter Pickup Location"
                        android:singleLine="true"
                        android:ellipsize="end"
                        android:textColor="@color/warm_grey"
                        android:textSize="14sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toEndOf="@id/iv_origin"
                        app:layout_constraintTop_toTopOf="parent" />
                </androidx.constraintlayout.widget.ConstraintLayout>

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_places"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:overScrollMode="never"
                    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/layoutPickupLocation" />
            </androidx.constraintlayout.widget.ConstraintLayout>

This is how I am submitting items to my list of RecyclerView:

 private fun submitSearchResult(it: List<MultipleLocation>?) {
        mLocationSearchAdapter.submitList(it?.map {
            DataItemLocationSearchListing.DefaultItemListing(
                    it
            )
        })
        rvSearchLocation.post(Runnable { mLocationSearchAdapter.notifyDataSetChanged() })
    }

Any sort of help would be highly appreciated.


Solution

  • Kindly replace your notifyDataSetChanged() with the notifyItemChanged(positionOfYourList).