title: Adding Long Press Listner to Listview inside a Recycler view
body: <p>I have been searching a lot of tutorials to implement an on item long press Listener on a <code>Listview</code> which is Inside a <code>RecyclerView</code>. So far I had no luck.
  I want a menu to more ap after holding the List Item for some time. I am attaching my code here please help me with it.</p>
  
  <p>I have added my complete code Including the MainAcyivity. 
  I have a tabbed view which contains 3tabs. Inside the tab view, there is a fragment which contains a Listview. </p>
  
  <p>I want the List to be long pressed to bring a popup menu which has as add or delete options. </p>
  
  <p>MainActivity.java</p>
  
  <pre><code>package tabbardemo.com.materialdesigntabs_demo;
  
  import android.os.Bundle;
  import android.support.design.widget.TabLayout;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
  private static Toolbar toolbar;
  private static ViewPager viewPager;
  private static TabLayout tabLayout;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      viewPager = (ViewPager) findViewById(R.id.viewPager);
      setupViewPager(viewPager);
  
      tabLayout = (TabLayout) findViewById(R.id.tabLayout);
      tabLayout.setupWithViewPager(viewPager);//setting tab over viewpager
  
      //Implementing tab selected listener over tablayout
      tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
              viewPager.setCurrentItem(tab.getPosition());//setting current selected item over viewpager
              switch (tab.getPosition()) {
                  case 0:
                      Log.e("TAG","TAB1");
                      break;
                  case 1:
                      Log.e("TAG","TAB2");
                      break;
                  case 2:
                      Log.e("TAG","TAB3");
                      break;
              }
          }
  
          @Override
          public void onTabUnselected(TabLayout.Tab tab) {
          }
  
          @Override
          public void onTabReselected(TabLayout.Tab tab) {
          }
      });
  }
  
  
  //Setting View Pager
  private void setupViewPager(ViewPager viewPager) {
      ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
      adapter.addFrag(new DummyFragment("Inbox"), "Inbox");
      adapter.addFrag(new EventsFragment("QA"), "QA");
      adapter.addFrag(new EventsFragment("Events"), "Events");
      viewPager.setAdapter(adapter);
  }
  
  
  //View Pager fragments setting adapter class
  class ViewPagerAdapter extends FragmentPagerAdapter {
      private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();//fragment arraylist
      private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();//title arraylist
  
      public ViewPagerAdapter(FragmentManager manager) {
          super(manager);
      }
  
      @Override
      public Fragment getItem(int position) {
          return mFragmentList.get(position);
      }
  
      @Override
      public int getCount() {
          return mFragmentList.size();
      }
  
  
      //adding fragments and title method
      public void addFrag(Fragment fragment, String title) {
          mFragmentList.add(fragment);
          mFragmentTitleList.add(title);
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mFragmentTitleList.get(position);
      }
      }
  }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/coordinatorLayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"&gt;
  
  &lt;!-- AppBar Layout   --&gt;
  &lt;android.support.design.widget.AppBarLayout
      android:id="@+id/appBarLayout"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="fill_parent"
          android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"
          app:layout_scrollFlags="scroll|enterAlways"
          app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /&gt;
      &lt;!-- Tab Layout for creating tabs --&gt;
      &lt;android.support.design.widget.TabLayout
          android:id="@+id/tabLayout"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" /&gt;
  &lt;/android.support.design.widget.AppBarLayout&gt;
  &lt;!-- Helps handing the Fragments for each Tab --&gt;
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/viewPager"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>dummy_fragment.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@color/blue"
  android:gravity="center"
  android:orientation="vertical"&gt;
  
  &lt;!--  Recycler View  --&gt;
  &lt;android.support.v7.widget.RecyclerView
      android:id="@+id/recyclerView"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:scrollbars="none" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>DummyFragment.java</p>
  
  <pre><code>package tabbardemo.com.materialdesigntabs_demo;
  import android.content.Context;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v4.app.Fragment;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.view.GestureDetector;
  import android.view.LayoutInflater;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewGroup;
  
  import java.util.ArrayList;
  
  /**
   * Created by SONU on 16/09/15.
   */
  public class DummyFragment extends Fragment {
  private View view;
  
  private String title;//String for tab title
  
  private static RecyclerView recyclerView;
  
  private OnItemClickListener mListener;
  
  public interface OnItemClickListener {
      public void onItemClick(View view, int position);
  
      public void onLongItemClick(View view, int position);
  }
  
  
  public DummyFragment(String title) {
      this.title = title;//Setting tab title
  }
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      view = inflater.inflate(R.layout.dummy_fragment, container, false);
  
      setRecyclerView();
      return view;
  
  }
  //Setting recycler view
  private void setRecyclerView() {
  
      recyclerView = (RecyclerView) view
              .findViewById(R.id.recyclerView);
      recyclerView.setHasFixedSize(true);
      recyclerView
              .setLayoutManager(new LinearLayoutManager(getActivity()));//Linear Items
  
  
  
  
      ArrayList&lt;String&gt; arrayList = new ArrayList&lt;&gt;();
      for (int i = 0; i &lt; 20; i++) {
          arrayList.add(title+" Items " + i);//Adding items to recycler view
      }
      RecyclerView_Adapter adapter = new RecyclerView_Adapter(getActivity(), arrayList);
      recyclerView.setAdapter(adapter);// set adapter on recyclerview
  
  
  
  }
  
  }
  </code></pre>
  
  <p>RecyclerView_Adapter</p>
  
  <pre><code>package tabbardemo.com.materialdesigntabs_demo;
  
  import android.content.Context;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import java.util.ArrayList;
  
  /**
   * Created by SONU on 10/09/15.
   */
  public class RecyclerView_Adapter extends
      RecyclerView.Adapter&lt;DemoViewHolder&gt; {
  private ArrayList&lt;String&gt; arrayList;
  private Context context;
  
  
  private OnItemClickListener mListener;
  
  public interface OnItemClickListener {
      public void onItemClick(View view, int position);
  }
  
  
  
  public RecyclerView_Adapter(Context context,
                              ArrayList&lt;String&gt; arrayList) {
      this.context = context;
      this.arrayList = arrayList;
  }
  
  
  
  @Override
  public int getItemCount() {
      return (null != arrayList ? arrayList.size() : 0);
  
  }
  
  @Override
  public void onBindViewHolder(DemoViewHolder holder,
                               int position) {
  
  
      final DemoViewHolder mainHolder = (DemoViewHolder) holder;
      //Setting text over textview
     // mainHolder.bind(arrayList.get(position), listener);
      mainHolder.title.setText(arrayList.get(position));
  
  
  
  }
  
  @Override
  public DemoViewHolder onCreateViewHolder(
          ViewGroup viewGroup, int viewType) {
      LayoutInflater mInflater = LayoutInflater.from(viewGroup.getContext());
  
      ViewGroup mainGroup = (ViewGroup) mInflater.inflate(
              R.layout.item_row, viewGroup, false);
      DemoViewHolder mainHolder = new DemoViewHolder(mainGroup) {
          @Override
          public String toString() {
              return super.toString();
          }
      };
  
  // 13805 ////////////////////////////////
          return mainHolder;
  
      }
  
  
  }
  </code></pre>
  
  <p>DemoViewHolder.java</p>
  
  <pre><code>package tabbardemo.com.materialdesigntabs_demo;
  
  import android.support.v7.widget.RecyclerView;
  import android.view.View;
  import android.widget.TextView;
  
  /**
   * Created by SONU on 31/08/15.
   */
  public abstract class DemoViewHolder extends RecyclerView.ViewHolder {
  
  
  public TextView title;
  
  
  public DemoViewHolder(View view) {
      super(view);
  
  
      this.title = (TextView) view.findViewById(R.id.cardTitle);
  
      }
  
  }
  </code></pre>
  
  <p>ite_row.xml</p>
  
  <p>
  </p>
  
  <pre><code>&lt;RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;ImageView
          android:id="@+id/iv_image"
          android:padding="10dp"
          android:layout_height="match_parent"
          android:layout_width="wrap_content"
          android:src="@mipmap/ic_launcher"&gt;
      &lt;/ImageView&gt;
  
  &lt;TextView
      android:id="@+id/cardTitle"
      android:layout_toRightOf ="@+id/iv_image"
      android:layout_width="fill_parent"
      android:layout_height="match_parent"
      android:padding="15dp"
      android:text="Card Title"
      android:textColor="#000000"
      android:textSize="17sp" &gt;&lt;/TextView&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>