How to Filter a RecyclerView with SearchView - Android Studio Tutorial

Coding in Flow · 213K views · 2018 · 16:37

Open on YouTube

Software (other)Web developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users cite it as the tutorial they followed when building RecyclerView search, and link it when their implementation of the Filterable adapter pattern from the video doesn't work.

Recommended by 0 people across 0 different months, 2019 to 2022.

What it is

A 16-minute Android Studio tutorial by Coding in Flow on filtering a RecyclerView in real time with a SearchView in the app bar. It adds an expandable SearchView to the options menu, makes the adapter implement Filterable with a custom Filter, and wires it up with an OnQueryTextListener.

What people said

Cites raouf · 2019-04 · Stack Overflow · on “how can I make the getFilter function in an adapter to be recognized in a searchview querytextlistner?”

I am working with kotlin searchview to filter a recyclerview, I literally copied the code from 3 people and it didn't work, the probleme is that it doesn't recognise the getFilter() function when I use it [LINK] [LINK] [this video] (this one is a javacode one but i converted it) and this is my github repo : [LINK] override fun onCreateOptionsMenu(menu: Menu?): Boolean { var inflater : MenuInflater = getMenuInflater() inflater.inflate(R.menu.menu_main, menu) var searchItem : MenuItem = menu!!.findItem(R.id.action_search) val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager val searchView = menu.findItem(R.id.action_search).actionView as SearchView searchView.setSearchableI

Cites Alexandru Stroescu · 2019-07 · Stack Overflow · on “Android search view not behaving right on toolbar”

there you have the video that shows how my app actually behaves: [LINK] You see that when I click the search icon, it just moves it to the left side, then I need to click it again, then i need to click the x button 2 times before I actually get out of the search view, a complete mess. Here's how I want my search view to behave: [this video] MainActivity.java (only the relevant part) @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.options_menu, menu); MenuItem searchItem = menu.findItem(R.id.app_bar_search); SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE); SearchVie

Cites justKotlin123 · 2019-09 · Stack Overflow · on “Problem implementing Searchview in RecycleView in a fragment?”

Sorry for my bad English but it's not my first language. I have a fragment with a Recyclerview in it, and I'm trying to implement a searchview to filter the data. I tried following this tutorial -> [this video] But the searchview just doesn't work; it doesn't filter anything. This is the code I implemented in my fragment ("adat" is my adapter in the fragment) override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { val vista2 = inflater.inflate(R.menu.main, menu) var searchItem : MenuItem? = menu?.findItem(R.id.searchView) var searchView : SearchView = MenuItemCompat.getActionView(searchItem) as SearchView searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener{ ov

Cites guitarpanda · 2020-02 · Stack Overflow · on “Why does the clone() function show incompatible types when assigned in Constructor?”

I am working on an Ecommerce app and need to make filter and populate RecycleView following is my code for RecycleViewAdapter class: public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> implements Filterable { private static final String TAG = "RecyclerViewAdapter"; private ArrayList<Product> productArrayList; final private ArrayList<Product> productArrayListFull; private Context mContext; public RecyclerViewAdapter(Context context, ArrayList<Product> products){ this.productArrayList = products; this.mContext = context; this.productArrayListFull = productArrayList.clone(); } } productArrayListFull is just assigned and used to get access to all produ

Cites Tim Hannah · 2020-05 · Stack Overflow · on “Adding filtering/search to my RecyclerView”

I have a RecyclverView set up which works perfectly (it may not be the 'best practice' but it works) The RecyclerView method I implemented was from this [LINK] video For this I did the below: I have added a RecyclerView in my activity_main.xml layout with an id @+id/recycler_view Create a RecyclerView Adapter class called RecyclerViewAdapter Create a listitem layout called layout_listitem.xml This worked perfectly and pulls the information from a values xml called sheep.xml When you click on one of the items it loads activity GalleryActivity which presents the information from that item position in a new activity_gallery.xml layout. image examples below: [LINK] I want to add filtering/search

Cites Geekr · 2020-06 · Stack Overflow · on “SearchView with RecyclerView (App closes when back to fragment which contains the recyclerview)”

I have fragment contains Recyclerview and Searchview (in cardview not appbar), Regarding the search process, the application works normally, but the problem is When to go from this fragment that contains the recyclerview and back to it, the app closes. Logcat: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference at java.util.ArrayList.addAll(ArrayList.java:588) at com.quiltur.blocks.BlockListAdapter$3.publishResults(BlockListAdapter.java:174) The Adapter: public class BlockListAdapter extends RecyclerView.Adapter<BlockListAdapter.BlockViewHolder> implements Filterable { private FirebaseFirestore fire

Cites 5wixy · 2022-06 · Stack Overflow · on “Items don't reappear when removing search filter pattern Cardview”

I tried adding a search bar that makes the items disappear when they aren't being searched, and only items that contain the character that are typed in the search are left. The search works fine, but when I'm backspacing (like if I made a typo or wanted to search something else) the items don't reappear. I tried playing with the variables. I followed the guide of [this video] . package com.example.scannerapp; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Filter; import android.widget.Filterable; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget