title: How to get selected item from RecyclerView list?
body: <p>I have created a interface for extending functionality of Recycler View and making possible to listen click on every item of list, but i can't make it to work. Nothing happens when i click on any item. Here is my code:</p>
  
  <pre><code>// METHOD FOR INITIALIZATION OF RECYCLER VIEW
  public void initRecyclerView() {
      // SETTING ARRAY FOR CATEGORIES
      final CategoryItem categoryItem[] = { new CategoryItem("Birthday", R.drawable.birthday_image),
                                      new CategoryItem("Anniversary", R.drawable.anniversary_image),
                                      new CategoryItem("Anniversary", R.drawable.anniversary_image),
                                      new CategoryItem("Anniversary", R.drawable.anniversary_image),
                                      new CategoryItem("Anniversary", R.drawable.anniversary_image),
                                      new CategoryItem("Anniversary", R.drawable.anniversary_image),
                                      new CategoryItem("Anniversary", R.drawable.anniversary_image),
                                      new CategoryItem("Anniversary", R.drawable.anniversary_image)};
  
      // FINDING RECYCLER VIEW IN LAYOUT
      recyclerView = (RecyclerView) findViewById(R.id.list);
      recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
  
      adapter = new CategoriesListAdapter(categoryItem);
      recyclerView.setAdapter(adapter);
  
      // SETTING ON CLICK LISTENER ON ADAPTER
      adapter.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void setOnItemClick(View view, int position) {
              String clickedItem = String.valueOf(position);
              if ( clickedItem.equals("Birthday") ) {
                  Toast.makeText(MainActivity.this, "Clicked on Birthday!", Toast.LENGTH_SHORT).show();
              }
          }
      });
      recyclerView.setItemAnimator(new DefaultItemAnimator());
  
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p><em>adapter</em></p>
  
  <pre><code>public class CategoriesListAdapter extends RecyclerView.Adapter&lt;CategoriesListAdapter.ViewHolder&gt; {
  
  private CategoryItem[] categoryItems;
  private static OnItemClickListener onItemClickListener;
  
  public CategoriesListAdapter(CategoryItem[] categoryItems) {
      this.categoryItems = categoryItems;
  }
  
  @Override
  public CategoriesListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_row, parent, false);
      ViewHolder viewHolder = new ViewHolder(itemLayoutView);
      return viewHolder;
  }
  
  
  @Override
  public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
  
      viewHolder.txtViewTitle.setText(categoryItems[position].getTitle());
      viewHolder.imgViewIcon.setImageResource(categoryItems[position].getImage());
  
  }
  
  // inner class to hold a reference to each item of RecyclerView
  public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
      public TextView txtViewTitle;
      public ImageView imgViewIcon;
  
      public ViewHolder(View itemLayoutView) {
          super(itemLayoutView);
          txtViewTitle = (TextView) itemLayoutView.findViewById(R.id.title);
          imgViewIcon = (ImageView) itemLayoutView.findViewById(R.id.image);
          itemLayoutView.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          onItemClickListener.setOnItemClick(v, getAdapterPosition());
      }
  }
  
  public void setOnItemClickListener (final OnItemClickListener onItemClickListener) {
      this.onItemClickListener = onItemClickListener;
  }
  
  // Return the size of your itemsData (invoked by the layout manager)
  @Override
  public int getItemCount() {
      return categoryItems.length;
  }
  
  }
  </code></pre>
  
  <p><strong>INTERFACE:</strong></p>
  
  <pre><code>public interface OnItemClickListener {
  
  public void setOnItemClick(View view, int position);
  
  }
  </code></pre>
  
  <p>It should display toast message if birthday is selected, but it's not displaying anything. I'm instancing array of class and i don't know how to listen clicked item. The answers there didn't help me solving my problem.</p>