I have a ListView where each item is a TextView.
I want to enable the long press behaviour similar to an EditText that display
Here is the solution
override setOnLongClickListener
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textID.setTextIsSelectable(true)
textID. setOnLongClickListener {
val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Copied String", textID.text)
clipboardManager.setPrimaryClip(clip)
true // Or false if not consumed
}
}
the expected behavior will be like the image below