-1

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

Cœur
  • 37,241
  • 25
  • 195
  • 267

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,548
  • 1
  • 11
  • 20