title: Issue while using contextmenu with listview items in a popupwindow
body: <p>I am developing an android application, my proposal is have two clickable textviews on the page and when user press each of the textview, a listview in a popupwindow will shows under the textview, when user choose a listview item, the textview will be setText() as the name as user selected, when user perform long click on the textview or on the listview item, a contextmenu can be shown to allow user "edit"(jump to a new activity for that) or "delete" the selected item and after that the list adapter can update the list accordingly.
  I have finished the code of registerContextMenu for the textview and it works, but the context menu won't show after I added the same code to the listview, I also tried add OnCreateContextMenuListener to the listview but failed again. can any expert help to look into this? thanks a lot. 
  here is the code:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  import android.content.Intent;
  import android.graphics.Color;
  import android.graphics.Paint;
  import android.graphics.drawable.ColorDrawable;
  import android.os.Bundle;
  import android.view.ContextMenu;
  import android.view.Gravity;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ContextMenu.ContextMenuInfo;
  import android.view.View.OnClickListener;
  import android.view.View.OnCreateContextMenuListener;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.PopupWindow;
  import android.widget.TextView;
  import android.widget.Toast;
  import android.widget.AdapterView.AdapterContextMenuInfo;
  import android.widget.AdapterView.OnItemClickListener;
  
  /**
   * @author Allen
   * 
   *
   */
  public class ProfileActivity extends Activity {
      private TextView aTextView;
      private TextView bTextView;
      private View popupWindow;
      // to initial popupwindow width and height
      private final int popupWindowWidth = 400;
      private final int popupWindowHeight = 350;
  
      // the background drawable for popupWindow
      ColorDrawable blackBackground = new ColorDrawable(Color.BLACK);
  
      private PopupWindow aPW;
      private ListView aListView;
      private ArrayAdapter&lt;String&gt; aListViewAdapter;
  
      private List&lt;String&gt; popupNameList;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.profile_page);
          init();
          Toast.makeText(this, "Long press item to modify", Toast.LENGTH_SHORT).show();
      }
  
      private void init() {
          aTextView = (TextView) findViewById(R.id.aSelectionTextView);
          aTextView.setText("Pls select");
          aTextView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
          //to bTextView will be the same process, only the popupnamelist //will be the different list
          popupNameList = new ArrayList&lt;String&gt;();
  
          popupWindow = this.getLayoutInflater().inflate(R.layout.profile_popup_window, null);
  
          aPW = new PopupWindow(popupWindow, popupWindowWidth, popupWindowHeight);
  
          addOnClickListeners();
  
      }
  
      private void aSelection() {
          // TODO Auto-generated method stub
          popupNameList = new ArrayList&lt;String&gt;();
          popupNameList.add("abc");
          popupNameList.add("ABC");
          popupNameList.add("123");
  
          // to enable the outside click dismiss the PW
          aPW.setBackgroundDrawable(blackBackground);
          aPW.setOutsideTouchable(true);
          // to limit dispatching the click event.
          aPW.setFocusable(true);
  
          aListView = (ListView) popupWindow.findViewById(R.id.profile_popup_lstview);
          aListViewAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.profile_listview_item, popupNameList);
          aListView.setAdapter(aListViewAdapter);
  
          aListView.setLongClickable(true);
  
          this.registerForContextMenu(aListView);
  
          aListView.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  // TODO Auto-generated method stub
                  aTextView.setText(popupNameList.get(position));
                  aPW.dismiss();
              }
          });
  
          aListView.setOnCreateContextMenuListener(mListOnCreateContextMenuListener);
  
      }
  
      private void addOnClickListeners() {
          // TODO Auto-generated method stub
          aTextView.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  aSelection();
                  aPW.showAsDropDown(findViewById(R.id.aSelectionTextView), 0, -10, Gravity.START);
              }
          });
  
          this.registerForContextMenu(aTextView);
      }
  
      public void onLaunchDoneClick(View view) {
      }
  
      @Override
      public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
          // TODO Auto-generated method stub
          super.onCreateContextMenu(menu, v, menuInfo);
          // menu.setHeaderTitle("Operation");
          menu.add(0, 0, 0, getString(R.string.edit));
          menu.add(0, 1, 0, getString(R.string.delete));
  
      }
  
      private final OnCreateContextMenuListener mListOnCreateContextMenuListener = new OnCreateContextMenuListener() {
          @Override
          public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
              Toast.makeText(getApplicationContext(), "onCreateContextMenu()", 1000).show();
              menu.add(0, 0, 0, getString(R.string.edit));
              menu.add(0, 1, 0, getString(R.string.delete));
          }
      };
  
      @Override
      public boolean onContextItemSelected(MenuItem item) {
          // TODO Auto-generated method stub
          AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
          switch (item.getItemId()) {
          case 0:
              Toast.makeText(getApplicationContext(), popupNameList.get(menuInfo.position), 1000).show();
              aListViewAdapter.notifyDataSetChanged();
              break;
          case 1:
              break;
  
          default:
              return super.onContextItemSelected(item);
          }
  
          return true;
  
      }
  
  }
  </code></pre>
  
  <p>The layout xml is here:</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
   &lt;TextView
              android:id="@+id/bSelectionTextView"
              android:layout_width="wrap_content"
              android:layout_height="40dp"
              android:layout_alignEnd="@+id/aSelectionTextView"
              android:layout_alignStart="@+id/aSelectionTextView"
              android:layout_toRightOf="@+id/textView2"
              android:layout_below="@+id/aSelectionTextView"
              android:gravity="start|center"
              android:text="BSelectionTextView"
              android:textSize="20sp" /&gt;
  
          &lt;Button
              android:id="@+id/okButton"
              android:layout_width="wrap_content"
              android:layout_height="40dp"
              android:layout_below="@id/dSelectionTextView"
              android:layout_centerHorizontal="true"
              android:background="@drawable/my_button_style"
              android:gravity="center"
              android:onClick="onLaunchDoneClick"
              android:text="@string/Done"
              android:textSize="18sp"
              android:visibility="gone" /&gt;
  
          &lt;TextView
              android:id="@+id/textView1"
              android:layout_width="120dp"
              android:layout_height="40dp"
              android:layout_alignParentLeft="true"
              android:layout_marginTop="5dp"
              android:layout_alignParentTop="true"
              android:gravity="start|center"
              android:text="ASelection"
              android:textSize="18sp" /&gt;
  
          &lt;TextView
              android:id="@+id/textView2"
              android:layout_width="120dp"
              android:layout_height="40dp"
              android:layout_alignParentLeft="true"
              android:layout_below="@id/textView1"
              android:gravity="start|center"
              android:text="BSelection"
              android:textSize="18sp" /&gt;
  
          &lt;TextView
              android:id="@+id/aSelectionTextView"
              android:layout_width="200dp"
              android:layout_height="40dp"
              android:layout_alignParentTop="true"
              android:layout_marginTop="5dp"
              android:layout_marginLeft="10dp"
              android:layout_toRightOf="@id/textView1"
              android:clickable="true"
              android:gravity="start|center"
              android:text="ASelectionTextView"
              android:textSize="20sp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>