问题
I know this question is already been asked but still, it does not help me to resolve issue
I am getting issue while copy data to clipboard-manager
below is code
fun copyToClipboard(context: Context, text: CharSequence){
var clipboard: ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
var clip: ClipData = ClipData.newPlainText("label",text)
clipboard.primaryClip = clip!!
}
as @ianhanniballake suggested, I have already use use setPrimaryClip() with a non-null ClipData
like below
var clip: ClipData = ClipData.newPlainText("label",text)
clipboard.primaryClip = clip!!
But don't know why, still I am getting same error like
Val cannot be reassigned
回答1:
You must use method setPrimaryClip()
, for example:
clipboard?.setPrimaryClip(clip)
because field primaryClip
has only getter.
来源:https://stackoverflow.com/questions/61359729/val-can-not-be-reassigned-at-clipboardmanager-primaryclip