I wrote a workaround to this problem by popping up an Alert Dialog with the contents of the ListView row on longClick.
The alertdialog has a textview with
android:textIsSelectable="true"
android:focusable="true"
The user now can select/copy the text he wants from this dialog.
Codewise, something like this:
lvMsg.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int pos, long id) {
final SMessage sms = (SMessage)lvMsg.getItemAtPosition(pos);
final LayoutInflater layoutInflaterAndroid = LayoutInflater.from(ctx);
View mView = layoutInflaterAndroid.inflate(R.layout.copy_text_dialog, null);
AlertDialog.Builder alertDialogBuilderCopy = new AlertDialog.Builder(getActivity());
alertDialogBuilderCopy.setView(mView);
TextView copyTextView = (TextView) mView.findViewById(R.id.copyTextView);
copyTextView.setText(sms.getContent());
AlertDialog alertDialogAndroidCopy = alertDialogBuilderCopy.create();
alertDialogAndroidCopy.show();
}
}
Contents of copy_text_dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Long Press to Select Text"
android:gravity="center"
android:layout_width="match_parent"
android:paddingTop="15dp"
android:paddingBottom="10dp"
android:textSize="20sp"
android:textColor="@color/colorPrimary"
android:layout_height="wrap_content"
android:id="@+id/copyTextTitle"></TextView>
<TextView android:textAppearance="?android:attr/textAppearanceMedium"
android:text="No Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:paddingBottom="20dp"
android:gravity="center"
android:enabled="true"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
android:id="@+id/copyTextView"></TextView>
</LinearLayout>