title: How to programmatically invoke text selection UI on TextView?
body: <h2>Short summary</h2>
  
  <p>I have a <strong>context menu</strong> invoked by a <strong>longpress</strong> on a <code>TextView</code>, and it is preventing users from selecting text in the <code>TextView</code> (since the stock Android text selection UI is also invoked by a <strong>longpress</strong> and my context menu receives the <strong>longpress</strong> event before the text selector does).</p>
  
  <h2>Details</h2>
  
  <p>I have a <code>ListView</code> with a number or custom row views. Inside each row view is a <code>TextView</code> which displays a user comment. Each <code>TextView</code> has <code>android:textIsSelectable="true"</code>.</p>
  
  <p>In order to allow the user to edit their comment, I am using a <strong>context menu</strong> (that contains an "Edit Comment" menu item) that is invoked when the user performs a <strong>longpress</strong> on the row.</p>
  
  <p>However, I would also like users to have the option of selecting text in the comment. The problem is that, both the stock Android text-selection UI and my <strong>context menu</strong> are both invoked by a <strong>longpress</strong> on the comment, and my <strong>context menu</strong> consumes the <strong>longpress</strong> event first.</p>
  
  <p>What I would like to do is add a "Select Text" menu option to my <strong>context menu</strong> that would <strong>(a)</strong> select all the comment text and, <strong>(b)</strong> bring up the Android text selection UI.</p>
  
  <p>But, I have been unable to find a way to programmatically make Android bring up the text selection UI.</p>
  
  <p>To be clear : I do not simply want to select the text and put it in the clipboard. I want the user to see the text highlighted in blue, with the standard Android text selection handles / carets on it so they can manipulate the selected text area themselves.</p>
  
  <p>E.g.: I would like to do the following (this method is in a <code>Fragment</code>):</p>
  
  <pre><code>@Override
  public boolean onContextItemSelected(MenuItem item)
  {
      switch (item.getItemId())
      {
          case R.id.select_text:
  
              // Here I would like to select all text in the comment
              // and bring up the text selection UI
  
              return true;
  
          default:
              return super.onContextItemSelected(item);
      }
  }
  </code></pre>
  
  <p>I have tried the following without success :</p>
  
  <pre><code>AdapterView.AdapterContextMenuInfo info =  
      (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
  
  TextView comment = (TextView) info.targetView.findViewById(R.id.comment_text);
  comment.setSelectAllOnFocus(true);
  comment.requestFocus();
  comment.setSelectAllOnFocus(false);
  </code></pre>
  
  <p>Thanks for any help!</p>