title: how to filter searchview in a recyclerview based on two different object arraylist
body: <p>Currently, I need to do a search view in Android Studio. I was using recyclerview in order to display all my information. My searchview now can filter based on name but not state. </p>
  
  <p>(I think the problem is the Arraylist in loop only contains the name and link information but not the other four data (third constructor). Can anyone tell me how to filter two types of information(user can type either name or state in the same space) in one searchview? Thank you very much :).</p>
  
  <p>Here is my object class which consists of 3 types of constructors. </p>
  
  <pre><code>public A(){
  
      }
  
      public A(String name,String link){
          this.name = name;
  
          this.link = link;
      }
  
      public A(String cname,String ad,String ad2, String state){
  
          this.cname=cname;
          this.ad=ad;
          this.ad2=ad2;
          this.state=state;
  
      }
  </code></pre>
  
  <p>Here is my Java class</p>
  
  <pre><code>ArrayList&lt;A&gt; t;
  ArrayList&lt;A&gt; c;
  ArrayList&lt;String&gt; searchnamestate;
  
    databaseReference = FirebaseDatabase.getInstance().getReference();
          databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  
                  for (DataSnapshot dataSnapshot1 : dataSnapshot.child("alluser").child("thera").getChildren()) {
                      A a= dataSnapshot1.getValue(A.class);
                      tkey.add(dataSnapshot1.getKey());
  //add the name into an String arraylist named searchnamestate             searchnamestate.add(dataSnapshot1.getValue(A.class).getName().toLowerCase());
                      t.add(a);
                  }
                  for (DataSnapshot dataSnapshot1 : dataSnapshot.child("company").getChildren()) {
                      A comp = dataSnapshot1.getValue(A.class);
  //add the state into an String arraylist named searchnamestate                    searchnamestate.add(dataSnapshot1.getValue(A.class).getState().toLowerCase());
                     c.add(comp);
                  }
  
                  adapter = new MyRecyclerViewAdapter(MainActivity.this, t,c, tkey);
                  rv.setAdapter(adapter);
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
                  Toast.makeText(getApplicationContext(), "Oh no!", Toast.LENGTH_SHORT).show();
              }
          });
  
  //searchview filter the information display in recyclerview based on what type
  //in the searchview
  search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
              @Override
              public boolean onQueryTextSubmit(String query) {
                  return false;
              }
  
              @Override
              public boolean onQueryTextChange(String newText) {
                  //    adapter.getFilter().filter(newText);
  
                  String newquery= newText.toLowerCase();
                  for(int i=0; i&lt;searchnamestate.size();i++) {
                      if (searchnamestate.get(i).contains(newquery)) {
                          adapter.filter(newquery);
                      }
                      else{
                        // Toast.makeText(MainActivity.this, "No Match found", Toast.LENGTH_LONG).show();
                      }
                  }
  
                  return false;
              }
          });
  
  
      }
  </code></pre>
  
  <p>Here is my adapter class</p>
  
  <pre><code> ArrayList&lt;Therapist&gt; tlist;
      ArrayList&lt;Therapist&gt; newtlist;
      ArrayList&lt;Therapist&gt; complist;
  
  //the t is using the second constructor while comp is the third constuctor in //Object class
   public MyRecyclerViewAdapter(Context c, ArrayList&lt;A&gt; t, ArrayList&lt;A&gt; comp, ArrayList&lt;String&gt; tk ){
          context=c;
          tlist=t;
          complist=comp;
  //add all the element from tlist into newtlist
          this.newtlist = new ArrayList&lt;A&gt;();
          this.newtlist.addAll(t);
  tkey=tk;
  
      }
  
   public void filter(String findtext) {
          //  findtext = findtext.toLowerCase(Locale.getDefault());
          tlist.clear();
          if (findtext.length() == 0) {
              tlist.addAll(newtlist);
          } else {
              for (A wp : newtlist) {
  //if the name type in searchview match name that stored in newtlist, it can filter based in name
                  if (wp.getName().toLowerCase(Locale.getDefault()).contains(findtext)) {
                      tlist.add(wp);
                  }
  
              }
          }
          notifyDataSetChanged();
      }
  
   @Override
      public int getItemCount() {
          return tlist.size();
      }
  </code></pre>