I am adding a TextView
to a floating window which has attribute android:textisselectable
.
mWindowManager.addView(textView, params);
Eveything is working fine except I cannot copy text on long press. The strange part is that it is working fine in Galaxy Tab but not on any other 5 inch phones I have.
I think it's a version problem. The Galaxy Tab has a version more than Honeycomb whereas the 5 inches screen may be Honeycomb or lower.
Try this code:
TextView textView;
String stringToBeExtracted;
int startingIndex=textView.getSelectionStart();
int endingIndex=textView.getSelectionEnd();
stringToBeExtracted = stringYouExtracted.subString(startingIndex, endingIndex);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(stringToBeExtracted);
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Text Copied", stringToBeExtracted);
clipboard.setPrimaryClip(clip);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With