I am modifying an old Android app. I have GPS lat and long stored in a string value and displayed to the user in an editable text field when it is resolved. I want to add a button that simply takes the value of a string and copies it to the clipboard.
I looked at this: How to programmatically copy text in an Android app?
But not sure how to implement it. Any help would be wonderful, I have not touched much development in this area recently!
thanks
Edit:
//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); }
I get this error: http://i.imgur.com/sQ4um.jpg
Grump source share