-1

How to copy the text present in a particular text view to clipboard when a button is pressed?

Cœur
  • 34,719
  • 24
  • 185
  • 251

1 Answers1

0

try below code on button click

String stringcopy = textView.getText().toString();
int startIndex = textView.getSelectionStart();
int endIndex = textView.getSelectionEnd();
stringcopy = stringcopy.subString(startIndex, endIndex);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(stringcopy);
Munir
  • 2,563
  • 1
  • 8
  • 19