title: Button to copy the value of a string to the clipboard
body: <p>I'm modifying an old Android application.  I have a GPS lat and long being stored in a string value and displayed to the user in a non-editable text box when it resolves.  I want to add a button which simply takes the value of the string, and copies it to the clipboard.</p>
  
  <p>I've looked at this:   <a href="https://stackoverflow.com/questions/238284/how-to-copy-text-programatically-in-my-android-app">How to copy text programmatically in my Android app?</a></p>
  
  <p>But not sure how to implement it. Any help would be great, I haven't touched much development in this area recently!</p>
  
  <p>Thanks</p>
  
  <p>Edit: </p>
  
  <pre><code>    //Set button (inside oncreate method)
      Button button = (Button)this.findViewById(R.id.buttoncopylocation);
      button.setOnClickListener(this);
  
  //Code added in onClick method
  @Override
  public void onClick(View arg0) {
      // TODO Auto-generated method stub
      ClipboardManager clipboard = (ClipboardManager)   getSystemService(Context.CLIPBOARD_SERVICE);
      ClipData clip = ClipData.newPlainText("Copied", mycoords);
      clipboard.setPrimaryClip(clip);
  }
  </code></pre>
  
  <p>I'm getting this error:  <a href="https://i.imgur.com/sQ4um.jpg" rel="nofollow noreferrer">http://i.imgur.com/sQ4um.jpg</a></p>