title: ListView in Fragment Context Menu
body: <p>I have <code>ListView</code> that is within a <code>Fragment</code>. I have been attempting to add a <code>ContextMenu</code> to edit and delete items from the list. The list items are clickable but no menu appears. I tried adding <code>if (getUserVisibleHint()) {</code> but was unsuccessful. Thanks in advance for your input.</p>
  
  <pre><code>    public static class FragmentS extends Fragment {
  
      private ListView saveListView;
      private List&lt;LiftSave&gt; LiftSaves = new ArrayList&lt;LiftSave&gt;();
      private static final int EDIT = 0, DELETE = 1;
  
      int longClickedItemIndex;
      DatabaseHandler dbHandler;
      ArrayAdapter&lt;LiftSave&gt; saveAdapter;
  
      public FragmentS() {
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.listview_s,
                  container, false);
          saveListView = (ListView) rootView.findViewById(R.id.saveListView);
  
          DatabaseHandler dbHandler;
          dbHandler = new DatabaseHandler (getActivity().getApplicationContext());
          if (dbHandler.getLiftSavesCount() != 0)
              LiftSaves.addAll(dbHandler.getAllLiftSaves());
  
          populateList();
  
          saveListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
              @Override
              public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  longClickedItemIndex = position;
                  return false;
              }
          });
          return rootView;
      }
  
      private void populateList() {
          ArrayAdapter&lt;LiftSave&gt; saveAdapter = new SaveListAdapter();
          saveListView.setAdapter(saveAdapter);
      }
  
      public class SaveListAdapter extends ArrayAdapter&lt;LiftSave&gt; {
              public SaveListAdapter() {
                  super(getActivity(), R.layout.listview_item, LiftSaves);
              }
  
              @Override
              public View getView(int position, View view, ViewGroup parent) {
                  if (view == null)
                      view = getActivity().getLayoutInflater().inflate(R.layout.listview_item, parent, false);
  
                  LiftSave currentLiftSave = LiftSaves.get(position);
  
                  TextView liftName = (TextView) view.findViewById(R.id.liftName);
                  liftName.setText(currentLiftSave.getLiftName());
                  TextView maxValue = (TextView) view.findViewById(R.id.maxValue);
                  maxValue.setText(currentLiftSave.getMaxValue());
                  TextView weightAndReps = (TextView) view.findViewById(R.id.weightAndReps);
                  weightAndReps.setText(currentLiftSave.getRepsAndWeight());
                  TextView liftNotes = (TextView) view.findViewById(R.id.liftNotes);
                  liftNotes.setText(currentLiftSave.getLiftNotes());
                  TextView date = (TextView) view.findViewById(R.id.todayDate);
                  date.setText(currentLiftSave.getTodayDate());
  
                  return view;
              }
  
      }
      public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
          super.onCreateContextMenu(menu, view, menuInfo);
  
          menu.setHeaderIcon(R.drawable.pencil_icon);
          menu.setHeaderTitle("Save Options");
          menu.add(Menu.NONE, EDIT, menu.NONE, "Edit Save");
          menu.add(Menu.NONE, DELETE, menu.NONE, "Delete Save");
      }
  
      public boolean onContextItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case EDIT:
                  // TODO: Add save edit code
                  break;
              case DELETE:
                  dbHandler.deleteLiftSave(LiftSaves.get(longClickedItemIndex));
                  LiftSaves.remove(longClickedItemIndex);
                  saveAdapter.notifyDataSetChanged();
                  break;
          }
  
          return super.onContextItemSelected(item);
      }
  }
  </code></pre>
  
  <p>XML:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".TabbedActivity$FragmentS"
  android:background="@android:color/holo_blue_dark"&gt;
  
  &lt;LinearLayout
  android:id="@+id/tabSaveList"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:text="Saved Maxes"
      android:id="@+id/textView"
      android:layout_gravity="center"
      android:layout_marginTop="10dp"
      android:textColor="#fffaf4a1"
      android:textStyle="bold" /&gt;
  
     &lt;ListView
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:id="@+id/saveListView" /&gt;
  
  
     &lt;/LinearLayout&gt;
     &lt;/RelativeLayout&gt;
  </code></pre>