将字符串值复制到剪贴板的按钮 [英] Button to copy the value of a string to the clipboard
问题描述
我正在修改旧的Android应用程序。我有一个GPS经纬度,并且长时间存储在字符串值中,并在解析后在不可编辑的文本框中显示给用户。我想添加一个仅获取字符串值并将其复制到剪贴板的按钮。
I'm modifying an old Android application. I have a GPS lat and long being stored in a string value and displayed to the user in a non-editable text box when it resolves. I want to add a button which simply takes the value of the string, and copies it to the clipboard.
我已经看过了:如何在Android应用中以编程方式复制文本?
但不确定如何实现它。任何帮助都将是很大的,我最近在这方面没有取得太大进展!
But not sure how to implement it. Any help would be great, I haven't touched much development in this area recently!
谢谢
编辑:
//Set button (inside oncreate method)
Button button = (Button)this.findViewById(R.id.buttoncopylocation);
button.setOnClickListener(this);
//Code added in onClick method
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Copied", mycoords);
clipboard.setPrimaryClip(clip);
}
我遇到此错误: http://i.imgur.com/sQ4um.jpg
推荐答案
如果只是Text,则非常简单。
If it is just Text, it is very simple.
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label","Your Text");
clipboard.setPrimaryClip(clip);
有关更多信息,请查看此链接
For further Information check out this link
这篇关于将字符串值复制到剪贴板的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!