How to implement searchView widget in android Studio through Recycleview?

Please Share On:

Today, I am going to show you how can you implement your searchView widget through recyclerView in android studio.

1) Create your seachView.xml

Here, add your searchView XML code where you want to add your searchView field.


2) Coding Parts

Now, let’s move to the code section. Follow these steps to make your seachView work.

Steps to follow:

2.1) Make your adapter implements Filterable. See an example below:

public class CollectExpandableListAdapter extends BaseExpandableListAdapter implements Filterable {
//......Your all code goes here..

2.2) Add the below line

private List<Parent> originalList;

Now, your looks like below:

public class CollectExpandableListAdapter extends BaseExpandableListAdapter implements Filterable {
    private static final String TAG = "tag";
    private final Context _context;
    private List<Parent> _listDataHeader; // header title
    private List<Parent> originalList;
    private final HashMap<Parent, List<Child>> _listDataChild;

//...Rest code...

2.3) Add the below code to your Activity class.

 SearchView searchView;

// initialize the variable
       searchView = view.findViewById(;

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            public boolean onQueryTextSubmit(String query) {
                return false;
            public boolean onQueryTextChange(String newText) {
                if ( TextUtils.isEmpty ( newText ) ) {
                } else {
                return true;

2.4) Finally, write some code in your adapter class. Copy the below code:

 public Filter getFilter() {
        return new Filter() {
            protected FilterResults performFiltering(CharSequence constraint) {
                final FilterResults filterResults= new FilterResults();
                final List<Parent> results = new ArrayList<Parent>();
                if (originalList == null)
                    originalList = _listDataHeader;
                if (constraint != null) {
                    assert originalList != null;
                    if (originalList.size() > 0) {
                        for (final Parent item : originalList) {
                            if (item.getPostcode().toLowerCase().contains(constraint.toString()) ||
                                    (item.getAddress().toLowerCase().contains(constraint.toString())) ||
                    filterResults.values = results;
                return filterResults;

            protected void publishResults(CharSequence constraint, FilterResults results) {
                _listDataHeader = (ArrayList<Parent>) results.values;


That’s it. You have successfully created your searchView working. Now check your searchView and see the results.

You may be interested in the following topics:

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright @2023. All Right Reserved.

Social media & sharing icons powered by UltimatelySocial