I'm trying to copy text in recyclerview to clipboard. can anyone help me.
val myClipboard = rvItemsList.getContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val myClip = ClipData.newPlainText("label", rvItemsList.toString()) myClipboard.setPrimaryClip(myClip)
this is the code i used. when trying to print i'm getting result I/System.out: ClipData { text/plain "label" {T:androidx.recyclerview.widget.RecyclerView{1d0e7d4 VFED..... ........ 55,809-1025,1768 #7f08015b app:id/rvItemsList}} }
values in the recycler view is productname and rate image of app with recyclerview
CodePudding user response:
The issue here that when you call rvItemsList.toString it will return default toString() method on the object.The output is, class name, then ‘at’ sign, and at the end hashCode of object. If want to copy value just add click listener on your textview. e.g.:
textView.setText("your_value")
textView.setOnClickListener {
val myClipboard = rvItemsList.getContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val myClip = ClipData.newPlainText("label", your_value) myClipboard.setPrimaryClip(myClip)
}