Search code examples
androidandroid-recyclerviewsearchview

How to implement SearchView inside RecyclerView


I need to filter selected values from RecyclerView.I am using RecyclerView and SearchView.

activity_main.xml
 <android.support.v7.widget.SearchView
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:id="@+id/search"
   android:hint="Enter any location"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp"
    android:layout_marginTop="50dp"
   />

dealer_item.xml

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    card_view:cardCornerRadius="4dp"
    card_view:contentPadding="15dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/dealer_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/dealer_loc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</android.support.v7.widget.CardView>

I am also having adapter,model and MainActivity java file. Please any one help me in this.


Solution

  • I have used below library for SearchView functionality, https://github.com/lapism/SearchView