title: Filter in SearchView not working in Android
body: <p>I am developing a search function, in which if I enter a search keyword in a searchview in android, i should get the list of the students matching my search word. I have written a code but getting an error. plaese let me know if i am using the adapter in a correct way.  my onCreateOptionsMenu function    </p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
  
      getMenuInflater().inflate(R.menu.options_menu, menu);
      SearchManager searchManager =(SearchManager) getSystemService(Context.SEARCH_SERVICE);
      SearchView searchView =(SearchView) menu.findItem(R.id.search).getActionView();
      searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  
  
  
      searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
              return false;
          }
  
          @Override
          public boolean onQueryTextChange(String newText) {
  
              StudentAdapter.getFilter().filter(newText);
              return true;
  
          }
      });
  
      return true;
  }
  </code></pre>
  
  <p>My studentAdapter class:</p>
  
  <pre><code>public class StudentAdapter extends
      RecyclerView.Adapter&lt;StudentAdapter.MyViewHolder&gt; implements
      Filterable {
  
  public List&lt;StudentModel&gt; new_list;
  private List&lt;StudentModel&gt; original_list;
  
  @Override
  public Filter getFilter() {
      return new Filter() {
          @SuppressWarnings("unchecked")
          @Override
          protected void publishResults(CharSequence constraint,
                                        FilterResults results) {
              new_list = (List&lt;StudentModel&gt;) results.values;
              StudentAdapter.this.notifyDataSetChanged();
          }
  
          @Override
          protected FilterResults performFiltering(CharSequence constraint) {
              FilterResults initial_results = new FilterResults();
  
              if (constraint == null || constraint.length() == 0) {
                  initial_results.values = original_list;
                  initial_results.count = original_list.size();
              } else {
  
                  // We perform filtering operation
                  List&lt;StudentModel&gt; filteredList = new ArrayList&lt;StudentModel&gt;();
  
                  // breaking string into words algorithm
                  String str = constraint.toString();
                  ArrayList&lt;String&gt; arrayOfWords = new ArrayList&lt;String&gt;();
                  int i = 0;
                  for (String word : str.split(" ")) {
                      arrayOfWords.add(word);
                      i++;
                  }
  
                  for (StudentModel model : original_list) {
                      boolean matched = false;
  
                      for (String element : arrayOfWords) {
  
  
                          if ((null != model.getName() &amp;&amp; model
                                  .getName().toUpperCase()
                                  .contains(element.toString().toUpperCase()))
  
  
                                  || ((null != model.getClass() &amp;&amp; model
                                  .getClass()
                                  .toUpperCase()
                                  .contains(
                                          element.toString()
                                                  .toUpperCase())))) {
                              matched = true;
                          } else {
                              matched = false;
                              break;
                          }
  
                      }
  
                  }
  
                  initial_results.values = filteredList;
                  initial_results.count = filteredList.size();
  
              }
  
              return initial_results;
          }
      };
      // return null;
  }
  
  public class MyViewHolder extends RecyclerView.ViewHolder {
      public TextView name, class;
  
      public MyViewHolder(View view) {
          super(view);
          name = (TextView) view.findViewById(R.id.name);
          class = (TextView) view.findViewById(R.id.class);
  
  
      }
  }
  
  public StudentAdapter(List&lt;StudentModel&gt; original_list) {
  
      this.original_list = original_list;
  }
  
  public List&lt;StudentModel&gt; getStudentlist() {
      return original_list;
  }
  
  @Override
  public StudentAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent,
                                                         int viewType) {
      View itemView = LayoutInflater.from(parent.getContext()).inflate(
              R.layout.original_list_row, parent, false);
  
      return new StudentAdapter.MyViewHolder(itemView);
  }
  
  @Override
  public void onBindViewHolder(StudentAdapter.MyViewHolder holder,
                               int position) {
      StudentModel original_list_vo = original_list.get(position);
  
      holder.name.setText(original_list_vo.getName());
      holder.class.setText(original_list_vo.getClass());
  
  
  }
  
  @Override
  public int getItemCount() {
      return original_list.size();
  }
  
  }
  </code></pre>
  
  <p>Any help will be appreciated, thanks in advance.</p>