title: Copy and share text into Clipboard from listview
body: <p>I am developing a basic Android App which parses an xml file from assets using SAXParser, and I have successfully parsed the xml.</p>
  
  <p>I then register the parsed text for Context using the following code:</p>
  
  <p>..........</p>
  
  <pre><code>this.registerForContextMenu(content);
  
  
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v,
          ContextMenuInfo menuInfo) {
      super.onCreateContextMenu(menu, v, menuInfo);
      menu.setHeaderTitle("Choose");
      menu.add(0, v.getId(), 0, "Copy");
      menu.add(0, v.getId(), 0, "Share");
  
      if (selectedText.size() &gt; 0) {
          menu.add(0, v.getId(), 0, "Copy");
          menu.add(0, v.getId(), 0, "Share");
      }
  
  }
  
  @Override
  public boolean onContextItemSelected(MenuItem item) {
      if (item.getTitle() == "Copy") {
          copySelectedText(getSelectedText());
          return true;
      } else if (item.getTitle() == "Share") {
          shareSelectedText(getSelectedText());
          return true;
      } else
          return false;
  }
  
  public boolean copySelectedText(String text) {
      ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
      ClipData clip = ClipData.newIntent(position, getIntent());
      clipboard.setPrimaryClip(clip);
      return true;
  }
  
  private void shareSelectedText(String text) {
      copySelectedText(null);
  
      Intent sharingIntent = new Intent(Intent.ACTION_SEND);
      sharingIntent.setType("text/plain");
      sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
      sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
              "Shared from MyApp");
      startActivity(Intent.createChooser(sharingIntent,
              "Sharing text using"));
  }
  
  public String getSelectedText() {
  
      //How do I code here?? }
  
      return null;
  }
  </code></pre>
  
  <p>Using the above code, Context menu works just fine when I long click on any portions of the parsed text. But my problem here is, I don't know to put the parsed text into clipboard. Could somebody help me out? Thanks in advance.</p>