- Forum posts: 8
Feb 4, 2016, 6:19:32 AM via Website
Feb 4, 2016 6:19:32 AM via Website
I am developing an android application. As a beginner i want your help to know how to copy selected text from textview to clipboard and paste it in another activity's edittext. I have tried with the following code to just copy it in clipboard. But the text is not copied. Can anyone please help me to solve this problem?
Thanks in Advance.
public ClipData converttext()
{
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
fulltext = returnedText;
int min = 0;
int max = returnedText.getText().length();
if (returnedText.isFocused()) {
final int selStart = returnedText.getSelectionStart();
final int selEnd = returnedText.getSelectionEnd();
min = Math.max(0, Math.min(selStart, selEnd));
max = Math.max(0, Math.max(selStart, selEnd));
}
// here is your selected text
final CharSequence selectedText = returnedText.getText().subSequence(min, max);
String text1 = selectedText.toString();
myClip = ClipData.newPlainText("text", text1);
clipboard.setPrimaryClip(myClip);
return myClip;
}
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.