Linked Questions

Popular Questions

Android - Implementing search filter to a RecyclerView

Asked by At

I need to implement a search feature based on an EditText to my RecyclerView. The list must be filtered while typing.

Here's the code : this is the adapter

public class DisplayAdapter extends RecyclerView.Adapter<DisplayAdapter.MyViewHolder>{
    private List<DataHolder> displayedList;
    public class MyViewHolder extends RecyclerView.ViewHolder{
        public TextView english_d;
        public MyViewHolder(View view){
              english_d = (TextView) view.findViewById(;
    public DisplayAdapter(List<DataHolder> displayedList){
        this.displayedList = displayedList;

    public MyViewHolder onCreateViewHolder(ViewGroup parent, int position)    {
    // create a layout
    View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);

    return new  MyViewHolder(itemView);
public void onBindViewHolder(MyViewHolder holder, int position) {
    DataHolder content = displayedList.get(position);
public int getItemCount() {
    return displayedList.size();

public class DataHolder {
private String english;

public DataHolder() {

public DataHolder(String english, String norse) {
    this.english = english;


public String getEnglish() {
    return english;

public void setEnglish(String english) {
    this.english = english;


and here's the Fragment that I am working with :

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_two_fragment, container, false);

        rv = (RecyclerView) view.findViewById(;

        inputSearch = (EditText) view.findViewById(;

        rv.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL));
        final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);


        disp_adapter = new DisplayAdapter(displayedList);

   return view;

Related Questions