title: Android - Long Click on RecyclerView item and ContextMenu
body: <p><strong>Problem:</strong> Cannot display a context menu showing a "delete" option" when longclicking on an item within a recyclerview</p>
  
  <p><strong>Result expected:</strong> see image below</p>
  
  <p>I'm almost there, but I'm missing something to make the contextMenu displayed on a longClick. </p>
  
  <p>Here is what I put in the viewHolder. I don't know what I should add and where to display the context menu in the onLongClick event.</p>
  
  <p>I skipped some lines of code and kept the ones relevant to my question.</p>
  
  <p>Thanks a lot for your assistance, </p>
  
  <p><strong>My interface to handle both types of clicks</strong></p>
  
  <pre><code>public interface OnItemClickListener{
      void onItemClick(int position);
  }
  
  public interface OnItemLongClickListener{
      void onItemLongClick(int position);
  }
  </code></pre>
  
  <p><strong>Viewholder code</strong></p>
  
  <pre><code>public void bindLongClick(final int position, final OnItemLongClickListener onItemLongClickListener) {
          itemView.setOnLongClickListener(new View.OnLongClickListener() {
              @Override
              public boolean onLongClick(View view) {
                  onItemLongClickListener.onItemLongClick(position);
                  return true;
              }
          });
      }
  
      @Override
      public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo){
              //menuInfo is null
          Log.v(LOG_TAG, "grrr");
          contextMenu.setHeaderTitle("Select The Action");
          contextMenu.add(0, view.getId(), 0, "Supprimer");//groupId, itemId, order, title
      }
  </code></pre>
  
  <p><strong>Adapter code</strong></p>
  
  <pre><code>@Override
      public void onBindViewHolder(CityListViewholder holder, int position) {
          holder.cityName.setText(cityArrayList.get(position).getCityName());
          holder.bindClick(position, onItemClickListener);
          holder.bindLongClick(position, onItemLongClickListener);
      }
  </code></pre>
  
  <p><strong>Then, in the activity - I skipped what is not relevant for my question</strong></p>
  
  <pre><code>mCityListAdapter = new CityListAdapter(mContext, cityArrayList, new CityListAdapter.OnItemClickListener() {
              @Override
              public void onItemClick(int position) {
                  mPager.setCurrentItem(position);
                  mDrawerLayout.closeDrawers();
              }
          }, new CityListAdapter.OnItemLongClickListener() {
              @Override
              public void onItemLongClick(int position) {
                  Log.v(LOG_TAG, "Position "+position);
              }
          });
  
          registerForContextMenu(mRecyclerView);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/hxNoj.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/hxNoj.jpg" alt="Expected result"></a></p>