Android RecyclerView GridLayoutManager onClick not working
<p>I ran into situation where the <code>RecyclerView</code> with <code>GridLayoutManager</code> is not working on <code>onClick()</code>. Like <code>ListView</code>, when I tap/click on a picture in a GridView, the onClick is not returning the single item details. When I click on a poster of a movie, it should only display the details about the particular movie, but instead it is displaying multiple movies details in a scroll view.</p>

<p>Look at the code below:</p>

<pre><code>public class MoviesGridAdapter extends RecyclerView.Adapter&lt;MoviesGridAdapter.PosterViewHolder&gt; {

    private Context context;
    private List&lt;Movies&gt; movieItems = new ArrayList&lt;&gt;();
    CustomItemClickListener listener;

    public MoviesGridAdapter(Context context, List&lt;Movies&gt; movieItems) {
        this.context = context;
        this.movieItems = movieItems;
    }


    @Override
    public PosterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.movies_grid_view_item, parent, false);
        final MoviesGridAdapter.PosterViewHolder vh = new MoviesGridAdapter.PosterViewHolder(view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Context zContext = context;
                Intent intent = new Intent(zContext, MoviesDetailActivity.class);
                Movies movies = movieItems.get(vh.getAdapterPosition());
                intent.putExtra("Items Selection", movies.getPosterPath());
                intent.putExtra("Items Selection 1", movies.getTitle());
                intent.putExtra("Items Selection 2", movies.getReleaseDate());
                intent.putExtra("Items Selection 3", movies.getVoteAverage());
                intent.putExtra("Items Selection 4", movies.getOverview());
                zContext.startActivity(intent);
            }
        });
        return vh;
    }

    public void setMoviesData(List&lt;Movies&gt; moviesData) {
        movieItems = moviesData;
        notifyDataSetChanged();
    }


    @Override
    public void onBindViewHolder(PosterViewHolder holder, final int position) {

        Context mcontext = context;
        Movies movies = movieItems.get(position);

        String posterUrlPath = movies.getPosterPath();

        Picasso.with(mcontext)
                .load(Constants.MOVIES_POSTER_URL + posterUrlPath)
                .into(holder.poster);

    }

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

    public class PosterViewHolder extends RecyclerView.ViewHolder {
        ImageView poster;    
        public PosterViewHolder(final View itemView) {
            super(itemView);
            poster = (ImageView) itemView.findViewById(R.id.movies_image_view_retrofit);
        }
    }

}
</code></pre>

<p>And following is the Fragment:</p>

<pre><code>public class MoviesFragment extends Fragment {

    private static final int COLUMN_COUNT = 2;
    private List&lt;Movies&gt; movieItems = new ArrayList&lt;&gt;();
    private RecyclerView recyclerView;
    private MoviesGridAdapter adapter;
    private Subscription subscription;

    public MoviesFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.movies_fragment_content, container, false);

        GridLayoutManager layoutManager = new GridLayoutManager(getContext(), COLUMN_COUNT);
        recyclerView = (RecyclerView) view.findViewById(R.id.movies_recycler_view);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(layoutManager);

        adapter = new MoviesGridAdapter(getActivity(), movieItems);
        recyclerView.setAdapter(adapter);

        return view;
    }

    @Override
    public void onStart() {
        super.onStart();

        if (movieItems != null) {
            adapter.setMoviesData(movieItems);
        }
        loadDate();
    }

    private void loadDate() {
        MoviesAPI api = RetrofitManager.getMoviesClient().create(MoviesAPI.class);

        subscription = api.getPopularMovies(APIKeys.MOVIES_DB_API_KEY)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(
                        new Action1&lt;MoviesResponse&gt;() {
                            @Override
                            public void call(MoviesResponse response) {
                                movieItems = response.getMovies();
                                adapter.setMoviesData(response.getMovies());
                            }
                        }, new Action1&lt;Throwable&gt;() {
                            @Override
                            public void call(Throwable throwable) {

                            }
                        }
                );
    }

}
</code></pre>

<p>Thank you guys for the attention. The solution I am looking is: when I click a picture from the grid view, I need the details about the particular movie like title, overview, releaseDate etc.</p>