本文介绍了无法在ClipboardManager primaryClip中重新分配Val的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这个问题已经存在问,但仍然不能解决我的问题
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
下面是代码
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!!
}
正如@ianhanniballake所建议的,我已经将setPrimaryClip()与非null的ClipData一起使用
as @ianhanniballake suggested, I have already use use setPrimaryClip() with a non-null ClipData
如下所示
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
推荐答案
您必须使用方法setPrimaryClip()
,例如:
You must use method setPrimaryClip()
, for example:
clipboard?.setPrimaryClip(clip)
因为字段primaryClip
仅具有吸气剂.
because field primaryClip
has only getter.
这篇关于无法在ClipboardManager primaryClip中重新分配Val的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!