title: Two recyclerView and one onClick showing the content of the clicked element of the respective recyclerView
body: <p><strong>Problem</strong><br>
  In my acitvity i have two recyclerViews showing popular movies and top rated movies respectively.
  When I click on a movie in a recyclerView, that movie is sent to an activity showing its details.
  I go back to the home and if I click on a movie of another recyclerView, the previously clicked movie is shown.
  I need to show the details of any clicked movie in any recyclerView.</p>
  <p>I have a single viewHolder (MovieViewHolder)</p>
  <pre><code> public class MovieViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
      //Widgets
      TextView title, rating;
      ImageView imageView;
  
      //Click listener
      OnMovieListener onMovieListener ;
  
      public MovieViewHolder(@NonNull View itemView, OnMovieListener onMovieListener) {
          super(itemView);
  
          this.onMovieListener = onMovieListener;
  
          title = itemView.findViewById(R.id.movie_title);
          imageView = itemView.findViewById(R.id.movie_img);
          rating = itemView.findViewById(R.id.rating_bar);
  
          itemView.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
  
          onMovieListener.onMovieClick(getAdapterPosition());
  
      }
  </code></pre>
  <p>An interface</p>
  <pre><code>public interface OnMovieListener {
  
      void onMovieClick(int position);
      void onCategoryClick(String category);
  
  
  }
  </code></pre>
  <p>This two Adapter:<br>
  This for popular movies</p>
  <pre><code>public class MovieRecyclerView extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
  
      private List&lt;MovieModel&gt; mMovies;
      private final OnMovieListener onMovieListener;
  
  
      public MovieRecyclerView(OnMovieListener onMovieListener) {
          this.onMovieListener = onMovieListener;
  
      }
  
  
      @NonNull
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.movie_item,
                  parent, false);
  
  
          return new MovieViewHolder(view, onMovieListener);
  
      }
  
      @Override
      public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
  
          ((MovieViewHolder) holder).title.setText(mMovies.get(position).getTitle());
          ((MovieViewHolder) holder).rating.setText(String.valueOf((float) (mMovies.get(position).getVote_average())));
  
          //ImageView: Using Glide Library
          Glide.with(holder.itemView.getContext())
                  .load(&quot;https://image.tmdb.org/t/p/w500/&quot;
                          + mMovies.get(position).getPoster_path())
                  .into(((MovieViewHolder) holder).imageView);
  
  
      }
  
      @Override
      public int getItemCount() {
          if (mMovies != null) {
              return mMovies.size();
          }
          return 0;
      }
  
      public void setmMovies(List&lt;MovieModel&gt; mMovies) {
          this.mMovies = mMovies;
          notifyDataSetChanged();
      }
  
      //Getting the id of the movie clicked
      public MovieModel getSelectedMovie(int position) {
          if (mMovies != null) {
              if (mMovies.size() &gt; 0) {
                  return mMovies.get(position);
              }
          }
          return null;
      }
  </code></pre>
  <p>This for top_rated</p>
  <pre><code>public class MovieLatestRecyclerView extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
  
      private List&lt;MovieModel&gt; mMoviesLatest;
      private OnMovieListener onMovieListener;
  
      public MovieLatestRecyclerView(OnMovieListener onMovieListener) {
          this.onMovieListener = onMovieListener;
      }
  
      @NonNull
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
         View  view = LayoutInflater.from(parent.getContext()).inflate(R.layout.movie_item,
                  parent, false);
          return new MovieViewHolder(view, onMovieListener);
  
      }
  
  
  
      @Override
      public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
  
          ((MovieViewHolder)holder).title.setText(mMoviesLatest.get(position).getTitle());
          ((MovieViewHolder)holder).rating.setText(String.valueOf((float) (mMoviesLatest.get(position).getVote_average())));
  
          //ImageView: Using Glide Library
          Glide.with(holder.itemView.getContext())
                  .load(&quot;https://image.tmdb.org/t/p/w500/&quot;
                          + mMoviesLatest.get(position).getPoster_path())
                  .into(((MovieViewHolder)holder).imageView);
  
      }
  
      @Override
      public int getItemCount() {
          if(mMoviesLatest != null) {
              return mMoviesLatest.size();
          }
          return 0;
      }
  
      public void setmMoviesLatest(List&lt;MovieModel&gt; mMoviesLatest) {
          this.mMoviesLatest = mMoviesLatest;
          notifyDataSetChanged();
      }
  
      //Getting the id of the movie clicked
      public MovieModel getSelectedMovie(int position){
          if(mMoviesLatest != null){
              if(mMoviesLatest.size() &gt; 0){
                  return mMoviesLatest.get(position);
              }
          }
          return null;
      }
  </code></pre>
  <p>In MainActivity i configure the recyclerViews with this method</p>
  <pre><code> private void ConfigureRecyclerView() {
          movieRecyclerViewAdapter = new MovieRecyclerView(this);
          movieLatestRecyclerViewAdapter = new MovieLatestRecyclerView(this);
  
          recyclerView_popular.setAdapter(movieRecyclerViewAdapter);
          recyclerView_popular.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
  
          recyclerView_latest.setAdapter(movieLatestRecyclerViewAdapter);
          recyclerView_latest.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
  
          //RecyclerView Pagination
          //Loading next page of api response
          recyclerView_popular.addOnScrollListener(new RecyclerView.OnScrollListener() {
              @Override
              public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                  if (!recyclerView.canScrollVertically(1)) {
                      //Here we need to display the next search result
                      movieListViewModel.searchNextPage();
                  }
              }
          });
          recyclerView_latest.addOnScrollListener(new RecyclerView.OnScrollListener() {
              @Override
              public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                  if (!recyclerView.canScrollVertically(1)) {
                      //Here we need to display the next search result
                      movieListViewModel.searchNextPage();
                  }
              }
          });
  
      }
  </code></pre>
  <p>And i use this for passing the selected movie to another activity</p>
  <pre><code> @Override
      public void onMovieClick(int position) {
          //WE don't need position of the movie in recyclerView
          // We need the ID of the movie in order to get all it's details
          Intent intent = new Intent(this, MovieDetails.class);
  
  
              intent.putExtra(&quot;movie&quot;, movieRecyclerViewAdapter.getSelectedMovie(position));
              startActivity(intent);
  
  
      }
  </code></pre>
  <p>Whoever you are reading my question I thank you for your time and I apologize for the certain banality and length.</p>