Filter Recyclerview From Array of objects Android
<p>i have RecyclerView get data from Array of objects , and i tried to make Filter in Recycler View adapter like this ,</p>

<pre><code>    public void filter(String filterString) {
    filterString = filterString.toLowerCase(Locale.getDefault());
    results.clear();
    if(filterString.length() == 0) {
    }
    else {
        for( ToDo item : stringArrayList){
            if(item.getTODO_TITLE().toLowerCase(Locale.getDefault()).contains(filterString)) {
                results.add(item.getTODO_TITLE() );
            }
        }
    }
    notifyDataSetChanged();
}
</code></pre>

<p>}</p>

<p>and when i call it in menu like this </p>

<pre><code>@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {

        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {

            return true;
        }

        @Override
        public boolean onQueryTextChange(String searchQuery) {

            if (searchQuery.length() != 0) {
                if (null != recyclerAdapter) {
                    recyclerAdapter.filter(searchQuery.toString());
                    todoRecyclerView.invalidate();
                    todoAdapter.notifyDataSetChanged();
                }
            }
            else{
            }
            return false;
        }
    });


    MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            return true;
        }
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }
    });
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.action_search) {

        return true;
    }
    return super.onOptionsItemSelected(item);
}}
</code></pre>

<p>its not working , and no error is showing !!! how i can solve this problem ???? </p>

<p>this is my code into recycler </p>

<pre><code>public class TodoList extends AppCompatActivity implements DialogFragUpdateListener {
RecyclerView todoRecyclerView;
private RecyclerView.Adapter todoAdapter;
private RecyclerView.LayoutManager todoLayoutManager;
public List&lt;ToDo&gt; results;
public List&lt;String&gt; list = new ArrayList&lt;&gt;();
TodoRecyclerAdapter recyclerAdapter;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_todo_list);

    todoRecyclerView = (RecyclerView)findViewById(R.id.todoRecyclerView);
    todoRecyclerView.setHasFixedSize(true);
    results= new ArrayList&lt;ToDo&gt;();
    todoLayoutManager = new LinearLayoutManager(this);
    todoRecyclerView.setLayoutManager(todoLayoutManager);
      getRetrofitObject();
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(TodoList.this,AddToDo.class);
            startActivity(intent);
        }
    });}

public void getRetrofitObject() {
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    APIService service = retrofit.create(APIService.class);
    Call&lt;Result&gt; call = service.getresults();
    call.enqueue(new Callback&lt;Result&gt;() {
        @Override
        public void onResponse(Call&lt;Result&gt; call, Response&lt;Result&gt; response) {
            results = response.body().getResults();
            todoRecyclerView.setAdapter(new TodoRecyclerAdapter(this,results));
        }
        @Override
        public void onFailure(Call&lt;Result&gt; call, Throwable t) {
            Log.d("onFailure", t.toString());
        }});}
</code></pre>

<p>Recycler View <strong>Adpater</strong></p>

<pre><code>public class TodoRecyclerAdapter extends RecyclerView.Adapter&lt;TodoRecyclerAdapter.ViewHolder&gt;  {

static List&lt;ToDo&gt; todoResults;
static Context context;
List&lt;String&gt; results;
private List&lt;String&gt; mDefaultCheeses;
private List&lt;ToDo&gt; mData;
private List&lt;ToDo&gt; originalData;
private ArrayList&lt;ToDo&gt; arrayList = null, stringArrayList;


public TodoRecyclerAdapter(Callback&lt;Result&gt; callback, List&lt;ToDo&gt; results) {
    this.todoResults = results;
     arrayList= (ArrayList&lt;ToDo&gt;) results;

}

@Override
public TodoRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.todo_items, null);
    ViewHolder viewHolder = new ViewHolder(itemLayoutView);
    return viewHolder;
}

@Override
public void onBindViewHolder(final TodoRecyclerAdapter.ViewHolder holder, final int position) {
    holder.todoTitle.setText(todoResults.get(position).getTODO_TITLE().toString());
    String priority = todoResults.get(position).getPriority().toString();
    if (priority.equals("Low")) {
        holder.todoImage.setImageResource(R.drawable.low);
    } else if (priority.equals("Normal")) {
        holder.todoImage.setImageResource(R.drawable.normal);
    } else if (priority.equals("High")) {
        holder.todoImage.setImageResource(R.drawable.high);
    }
}

@Override
public int getItemCount() {
    return todoResults.size();
}

public static class ViewHolder extends RecyclerView.ViewHolder {
    public TextView todoTitle;
    public ImageView todoImage;

    public ViewHolder(View itemLayoutView) {
        super(itemLayoutView);
        todoTitle = (TextView) itemLayoutView.findViewById(R.id.todo_title);
        todoImage = (ImageView) itemLayoutView.findViewById(R.id.imageView2);
    }
}

public void filter(String filterString) {
    filterString = filterString.toLowerCase(Locale.getDefault());
    results.clear();
    if(filterString.length() == 0) {
    }
    else {
        for( ToDo item : stringArrayList){
            if(item.getTODO_TITLE().toLowerCase(Locale.getDefault()).contains(filterString)) {
                results.add(item.getTODO_TITLE() );
            }
        }
    }
    notifyDataSetChanged();
}
</code></pre>

<p>}</p>