Start new Activity with onClick() in RecyclerView

I found the solution!:) There’s this way of handling item click in Recyclerview with itemView given within the ViewHolder class:

 public static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(LayoutInflater inflater, ViewGroup parent) {
            super(inflater.inflate(R.layout.fragment_channel, parent, false));
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Context context = v.getContext();
                    Intent intent = new Intent(context, ChannelDetailActivity.class);
                    context.startActivity(intent);
                }
            });
        }
    }

Leave a Comment