title: How to use onItemLongClick to show a context menu?
body: <p>I tried to get answer here but didn't get any perfect answer.
  I am trying to show context menu on <code>onItemLongClick</code> but no success as i am using both <code>onItemClick</code> and <code>onItemLongClick</code> </p>
  
  <p>i am using <code>onItemClick</code> to start a new activity but no success on both.</p>
  
  <p>Here is the code</p>
  
  <pre><code>    @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.all_contacts);  
  
      contactList = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
  
      new LoadAllContacts().execute();
  
      registerForContextMenu(getListView());
  
      ListView listView = getListView();
  
      listView.setOnItemLongClickListener(new OnItemLongClickListener() {
  
          @Override
          public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view,
                  int postion, long id) {
                  registerForContextMenu( view );
                  openContextMenu( view ); 
              return true;
          }
      });
      listView.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int postion, long id) {
              Intent intent = new Intent(AllContactsActivity.this, editContactActivity.class);    
          }
      });
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if(resultCode == 100)
      {
          Intent intent = getIntent();
          finish();
          startActivity(intent);
      }
  }
  
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v,
          ContextMenuInfo menuInfo) {
      super.onCreateContextMenu(menu, v, menuInfo);
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.listview_menu, menu);
  }
  @Override
  public boolean onContextItemSelected(MenuItem item) {
      switch (item.getItemId()) {
      case R.id.editContactMI:
          Intent i = new  Intent(getApplicationContext(), editContactActivity.class);
          i.putExtra(TAG_ID, cId);
          i.putExtra(TAG_NAME, cName);
          i.putExtra(TAG_CONTACT_NO, cNumber);
          startActivityForResult(i, 100);
          cId = null;
          cName = null;
          cNumber = null;
          break;
      case R.id.deleteContactMI :
          new DeleteContact().execute();
          break;
      case R.id.saveContactMI:
          break;
      default:
          cId = null;
          cName = null;
          cNumber = null;
          break;
      }
  
      return true;
  }
  </code></pre>