Val can not be reassigned at ClipboardManager primaryClip

梦想与她 提交于 2020-04-30 06:38:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!