0

I have a recycler view setup to display a list of contacts. The contacts are itself grouped according to initials. To manage the display of this, each recyclerview item, consists of a textView and a linearLayout. The textView holds the initial letter. And the LinearLayout holds the contacts starting with that letter.

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorGrayLight">

            <TextView
                android:id="@+id/itemRclContactsDisplayTvGroupLetter"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/_16sdp"
                android:layout_marginEnd="@dimen/_16sdp"
                android:layout_marginTop="@dimen/_8sdp"
                android:onClick="@{clickHandler::contactGroupClicked}"
                android:text="@{contactList.getGroupLetter()}"
                android:textSize="@dimen/_16sdp"
                android:textColor="@color/colorText1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:text="A" />

            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_8sdp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/itemRclContactsDisplayTvGroupLetter">

                <LinearLayout
                    android:id="@+id/itemRclContactsDisplayLlContactContainer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" />
            </androidx.cardview.widget.CardView>
        </androidx.constraintlayout.widget.ConstraintLayout>

This is the code for the recycler-view item layout. Now what I need to achieve is that I need to Implement a search feature here, while the user searches, after inputting the search string and pressing the search button, the list will scroll the specific contact to top of the screen if it is found. The problem lies here, I am able to scroll the recycler-view itself. But that is only possible according to the initials. And since there can be more than 100 contacts under a single initial, It does not gurante that just scrolling to the initial would make the searched contact come to view. So, is there a way to achieve what I am trying to do with this setup? or do I need to change my setup completely?

Arun123
  • 118
  • 6
  • Seems you need to implement filterable interface: https://www.androidhive.info/2017/11/android-recyclerview-with-search-filter-functionality/ – Nicola Gallazzi Jan 22 '21 at 11:44
  • i honestly don't understand exactly what you're trying to achieve... it sounds like you're able to scroll to a specific item already , based on whether or not it contains a specific initial, right ? are you saying you want to filter out results ? – a_local_nobody Jan 22 '21 at 11:45
  • 1
    @a_local_nobody its like this, each item in recycler-view, consists of a LinearLayout that holds the actual contacts. Say there are 100 contacts with initial A. That means a single item in the recycler-view has a LinearLayout that has 100 child views. What I need to do is to scroll the recycler-view to have say the 50th child in focus. I hope I was able to explain it. – Arun123 Jan 22 '21 at 11:53
  • @NicolaGallazzi yes, Currently I have implemented it with filterable as a placeholder. But I am sure the Client would want it to scroll, rather than filter the results. So I am a bit caught up. – Arun123 Jan 22 '21 at 11:56
  • @Arun123 scrollToPosition() not usefull here ? – DrHowdyDoo Jan 24 '21 at 09:16

0 Answers0