How do I enable standard copy paste for a TextView in Android?
This works for copy pre-Honeycomb:
import android.text.ClipboardManager;
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager cm = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(textView.getText());
Toast.makeText(context, "Copied to clipboard", Toast.LENGTH_SHORT).show();
}
});
How can i enable copy and Paste option in TextView in an App | Android Studio
Add this line to textview :
android:longClickable="true"
android:textIsSelectable="true"
In your Java class write this line to set it programmatically.
myTextView.setTextIsSelectable(true);
How to select and copy text by pressing long in textView?
Try this , its will work for you :
private ClipboardManager myClipboard;
private ClipData myClip;
//inside oncreate
myClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
mEditText.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
String text;
text = mEditText.getText().toString();
myClip = ClipData.newPlainText("text", text);
myClipboard.setPrimaryClip(myClip);
Toast.makeText(getApplicationContext(), "Text Copied",
Toast.LENGTH_SHORT).show();
return true;
}
});
Select and copy text in a TextView Android
Ok so, I found the problem by myself, I wasn't able to select because i have a
setMovementMethod(new ScrollingMovementMethod());
I tried to delete this one and it's work.
Thx for ur help
How to copy text programmatically in my Android app?
Use ClipboardManager#setPrimaryClip
method:
import android.content.ClipboardManager;
// ...
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", "Text to copy");
clipboard.setPrimaryClip(clip);
ClipboardManager
API reference
Related Topics
Google Glass Gdk: How to Communicate with Android Device
Pass Arraylist<? Implements Parcelable> to Activity
How to Resolve Java.Util.Zip.Zipexception
Differencebetween @Id and @+Id
Application Installation Failed in Android Studio
Spannablestringbuilder to Create String with Multiple Fonts/Text Sizes etc Example
Detecting Which Selected Item (In a Listview) Spawned the Contextmenu (Android)
Auto-Scrolling Textview in Android to Bring Text into View
Cannot Resolve Method Setlatesteventinfo
How to Use Android Progressbar in Determinate Mode
How to Change Action Bar Title Color in Code
Implementing Text Watcher for Edittext
How to Hide Underbar in Edittext
Android Install APK with Intent.View_Action Not Working with File Provider