title: Getting wrong position after Recyclerview filtering using SearchView
body: <p>I trying to add a SearchView to my app using the website:</p>
  
  <p><a href="http://www.tutorialsbuzz.com/2015/11/Android-Filter-RecyclerView-Using-SearchView-In-ToolBar.html" rel="nofollow">http://www.tutorialsbuzz.com/2015/11/Android-Filter-RecyclerView-Using-SearchView-In-ToolBar.html</a></p>
  
  <p>Yet, I'm unable to send the user to the right Recyclerview position after clicking to the filtered result:</p>
  
  <p><strong>For example</strong>: If a user searched for the 2nd result and he click it, the app will send him the next activity (details activity) using the 1st result instead for the 2nd result.</p>
  
  <p>Here are my app codes (<strong>ListAdapter.java</strong>):</p>
  
  <pre><code>public class ListAdapter extends RecyclerView.Adapter&lt;ListAdapter.GmailVH&gt; {
  
      ArrayList&lt; Information &gt; dataList;
      String letter;
      Context context;
  
      public ListAdapter(Context context, ArrayList&lt; Information &gt; dataList) {
          this.context = context;
          this.dataList = dataList;    
      }
  
      @Override
      public GmailVH onCreateViewHolder(ViewGroup viewGroup, int i) {
          View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item, viewGroup, false);
          return new GmailVH(view);
      }
  
      @Override
      public void onBindViewHolder(GmailVH gmailVH, int i) {
  
          Information current= dataList.get(i);
  
          gmailVH.title.setText(current.title);
  
          letter = String.valueOf(current.title2);
  
          TextDrawable drawable = TextDrawable.builder()
                  .buildRound(letter, generator.getRandomColor());
  
          gmailVH.letter.setImageDrawable(drawable);
    }
  
      @Override
      public int getItemCount() {
          return dataList == null ? 0 : dataList.size();
      }
  
      public Object getItem(int location) {
          return dataList.get(location);
      }
  
      class GmailVH extends RecyclerView.ViewHolder {
          TextView title;
          ImageView letter;
  
          public GmailVH(View itemView) {
              super(itemView);
              letter = (ImageView) itemView.findViewById(R.id.gmailitem_letter);
              title = (TextView) itemView.findViewById(R.id.gmailitem_title);
          }
      }
  
      public void setFilter(List&lt;Information&gt; informations) {
          dataList = new ArrayList&lt;&gt;();
          dataList.addAll(informations);
          notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p><strong>MainActivity.java</strong>:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity
          implements NavigationView.OnNavigationItemSelectedListener {
  
      RecyclerView recyclerView;
      ListAdapter adapter;
      private DrawerLayout mDrawerLayout;
      private ActionBarDrawerToggle mDrawerToggle;
  
      final ArrayList&lt; Information &gt; listData = new ArrayList&lt;&gt;();
  
      @Override
      protected void onCreate ( Bundle savedInstanceState ) {
  
          super.onCreate( savedInstanceState );
  
          setContentView( R.layout.activity_main );
  
  
          Toolbar toolbar = ( Toolbar ) findViewById( R.id.toolbar );
          setSupportActionBar( toolbar );
  
          mNavigationView = ( NavigationView ) findViewById( R.id.nav_view );
          mNavigationView.setNavigationItemSelectedListener( this );
  
          mDrawerLayout = ( DrawerLayout ) findViewById( R.id.drawer_layout );
          mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close );
          mDrawerLayout.addDrawerListener( mDrawerToggle );
          mDrawerToggle.syncState();
  
          recyclerView = ( RecyclerView ) findViewById( R.id.gmail_list );
  
          recyclerView.setLayoutManager( new LinearLayoutManager( this ) );
          recyclerView.setItemAnimator( new DefaultItemAnimator() );
  
  
          String[] title_array = getResources().getStringArray( R.array.title_array );
          String[] letters_array = getResources().getStringArray( R.array.letters_array );
  
  
          for ( int i = 0; i &lt; title_array.length &amp;&amp; i &lt; letters_array.length; i++ ) {
  
              Information feed = new Information();
  
              feed.title = title_array[ i ];
              feed.title2 = letters_array[ i ];
  
              listData.add( feed );
  
          }
  
  
          if ( adapter == null ) {
              adapter = new ListAdapter( this, listData );
              recyclerView.setAdapter( adapter );
          }
  
          recyclerView.addOnItemTouchListener( new RecyclerTouchListener( this, recyclerView, new ClickListener() {
  
              @Override
              public void onClick ( View view, int position ) {
  
                  Intent intent = new Intent( MainActivity.this, Name_info.class );
  
                  Bundle extras = new Bundle();
  
                  String[] title_array = getResources().getStringArray( R.array.title_array );
                  final String title_clicked = title_array[ position ];
  
                  String[] letters_array = getResources().getStringArray( R.array.letters_array );
                  final String letters_clicked = letters_array[ position ];
  
                  String[] letters_title_array = getResources().getStringArray( R.array.letters_title_array );
                  final String letters_title_clicked = letters_title_array [ position ];
  
                  intent.putExtras( extras );
                  intent.putExtra( "title_array", title_clicked );
                  intent.putExtra( "letters_array", letters_clicked );
                  intent.putExtra( "letters_title_array", letters_title_clicked );
  
                  ActivityCompat.startActivity( MainActivity.this, intent, extras );
  
              }
  
          }
          ) );
  
  
          if ( !didUserSeeDrawer() ) {
              showDrawer();
              markDrawerSeen();
          } else {
              hideDrawer();
          }
  
      }
  
  
      @Override
      public boolean onCreateOptionsMenu ( Menu menu ) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate( R.menu.main, menu );
  
            final SearchView searchView = ( SearchView ) MenuItemCompat.getActionView( item );
  
          searchView.setOnQueryTextListener(
                  new SearchView.OnQueryTextListener(){
  
                      @Override
                      public boolean onQueryTextSubmit(String query) {
                          return false;
                      }
  
                      @Override
                      public boolean onQueryTextChange(String newText) {
  
                          final ArrayList&lt;Information&gt; filteredModelList = filter(listData , newText);
                          adapter.setFilter(filteredModelList);
  
                          return true;
                      }
                  });
  
          MenuItemCompat.setOnActionExpandListener( item,
                                                    new MenuItemCompat.OnActionExpandListener() {
                                                        @Override
                                                        public boolean onMenuItemActionCollapse ( MenuItem item ) {
  // Do something when collapsed
                                                            adapter.setFilter( listData );
                                                            return true; // Return true to collapse action view
                                                        }
  
                                                        @Override
                                                        public boolean onMenuItemActionExpand ( MenuItem item ) {
  // Do something when expanded
                                                            return true; // Return true to expand action view
                                                        }
                                                    } );
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected ( MenuItem item ) {
          switch ( item.getItemId() ) {
  
              case android.R.id.home:
  
                  mDrawerLayout.openDrawer( GravityCompat.START );
                  return true;
  
  
  
          }
  
          return super.onOptionsItemSelected( item );
      }
  
  
  //...
  
              class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
  
  
                  private GestureDetector gestureDetector;
                  private ClickListener clickListener;
  
                  public RecyclerTouchListener ( Context context, final RecyclerView recyclerView, final ClickListener
                          clickListener ) {
  
                      this.clickListener = clickListener;
  
  
                      gestureDetector = new GestureDetector( context, new GestureDetector
                              .SimpleOnGestureListener() {
  
                          @Override
                          public boolean onSingleTapUp ( MotionEvent e ) {
                              return true;
                          }
  
                      } );
  
                  }
  
                  @Override
                  public boolean onInterceptTouchEvent ( RecyclerView rv, MotionEvent e ) {
  
                      View child = rv.findChildViewUnder( e.getX(), e.getY() );
  
                      if ( child != null &amp;&amp; clickListener != null &amp;&amp; gestureDetector.onTouchEvent( e ) )
  
                      {
  
                          clickListener.onClick( child, rv.getChildAdapterPosition( child ) );
  
                      }
  
                      return false;
                  }
  
                  @Override
                  public void onTouchEvent ( RecyclerView rv, MotionEvent e ) {
  
                  }
  
                  @Override
                  public void onRequestDisallowInterceptTouchEvent ( boolean disallowIntercept ) {
  
                  }
              }
  
              public interface ClickListener {
  
                  void onClick ( View view, int position );
  
              }
  
  
  
      private ArrayList&lt;Information&gt; filter(ArrayList&lt;Information&gt; models, String query) {
          query = query.toLowerCase();
  
          final ArrayList&lt;Information&gt; filteredModelList = new ArrayList&lt;&gt;();
          for (Information model : models) {
              final String text = model.getName().toLowerCase();
              if (text.contains(query)) {
                  filteredModelList.add(model);
              }
         }
          return filteredModelList;
      }
  }
  </code></pre>
  
  <p><strong>Information.java</strong></p>
  
  <pre><code>public class Information {
  
      String title;
      String title2;
  
      public String getName() {
          return title;
      }
  
  }
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <hr>
  
  <p><strong>Update with solution:</strong></p>
  
  <p>By adding the following code to <strong>Information.java</strong>:</p>
  
  <pre><code>public class Information {
  
      String title;
      String title2;
      String title3;
  
      public String getName() {
          return title;
      }
  
      public String getLetter() {
          return title2;
      }
  
      public String getLetter_title() {
          return title3;
      }
  }
  </code></pre>
  
  <p>And replacing String[] arrays &amp; putExtra in <strong>MainActivity.java</strong> with:</p>
  
  <pre><code>        Information information = (Information )adapter.getItem(position);
  
  
         intent.putExtra( "title_array", information.getName() );
         intent.putExtra( "letters_array", information.getLetter() );
         intent.putExtra( "letters_title_array", information.getLetter_title() );
  </code></pre>