Search functionality with recyclerview in android. 

Here is simple demo to make your recyclerview searchable. By following this demo you can implement search functionality to your RecyclerView in android. Here I got country list and display in Recyclerview.Follow these steps to implement search functionality with RecyclerView :

  1. Create new project with Android studio.
  2. Create xml file for MainActivity with RecyclerView and EditText to search.
  3. Create list to add in RecyclerView.
  4. Do ready RecyclerView.
  5. Add “addTextChangedListener” to EditText.
  6. Override “onTextChanged” with adapter.filter(s);
  7. Add filter(CharSequence sequence) to your adapter class.
  8. Now your ready to use your search with RecyclerView.

MainActivity code

private void init() {
        RecyclerView rvItems = (RecyclerView) findViewById(;
        rvItems.setLayoutManager(new LinearLayoutManager(this));
        ArrayList countryList = new ArrayList<>();
        for (String s : Locale.getISOCountries()) {
            countryList.add(new Locale("", s).getDisplayCountry(Locale.ENGLISH));
        final RvSearchDemoAdapter adapter = new RvSearchDemoAdapter(this, countryList);

        EditText etSearch = (EditText) findViewById(;
        etSearch.addTextChangedListener(new TextWatcher() {
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {


            public void onTextChanged(CharSequence s, int start, int before, int count) {

            public void afterTextChanged(Editable s) {


Adapter class

public class RvSearchDemoAdapter extends RecyclerView.Adapter {
    private ArrayList countries;
    private ArrayList countriesCopy;
    private LayoutInflater inflater;

    public RvSearchDemoAdapter(Context context, ArrayList countries) {
        this.countries = countries;
        this.countriesCopy = new ArrayList<>();
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    public RvSearchDemoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new RvSearchDemoHolder(inflater.inflate(R.layout.item_country, parent, false));

    public void onBindViewHolder(RvSearchDemoHolder holder, int position) {

    public int getItemCount() {
        return countries.size();

    public void filter(CharSequence sequence) {
        ArrayList temp = new ArrayList<>();
        if (!TextUtils.isEmpty(sequence)) {
            for (String s : countries) {
                if (s.toLowerCase().contains(sequence)) {
        } else {

Get detailed project from Github,

Share this content: