'Filtering RecycerView using SearchView in android [duplicate]

I'm trying to make an app that filters book titles. The filtering part works perfectly fine but the problem is when you start the app. I want to show all the titles in a recyclerView before filtering.

Adapter

public void filterList(List<Model> filterllist) {
    tileListData = filterllist;
    notifyDataSetChanged();
}

Main.java

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            filter(newText);
            return false;
        }
    });



private void filter(String text) {
    List<Model> filteredlist = new ArrayList<>();

    for (Model item : arrayList) {
        if (item.getTittle().toLowerCase().contains(text.toLowerCase())) {
            filteredlist.add(item);
        }
    }
    if (filteredlist.isEmpty()) {
        Toast.makeText(this, "No Data Found..", Toast.LENGTH_SHORT).show();
    } else {
        adapter.filterList(filteredlist);
    }
}

I have no clue how to fix this one. Please help out. I'm kind of new to the android platform. Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source