“标签”到底是什么? Android中的ClipData中的参数? [英] What exactly is "label" parameter in ClipData in Android?
问题描述
根据Android 文档,ClipData使用标签作为
ClippedData是包含一个或Item实例的复杂类型,每个实例可以容纳一个或多个数据项的表示。为了显示给用户,它还具有标签和图标表示。
然后它进一步将标签解释为剪辑数据中用户可见的标签,位于某些 API文档。但是,我仍然对标签的用法感到困惑。
该标签对用户如何显示?我应该如何使用?当我调用ClipData工厂方法 newPlainText(CharSequence标签,CharSequence文本)
时,应为该标签设置什么?例如:
private void copyToClipBoard(){
ClipboardManager剪贴板=(ClipboardManager)getSystemService(CLIPBOARD_SERVICE );
ClipData clip = ClipData.newPlainText(
文本标签,//我应该为此标签设置什么?
要复制的内容);
剪贴板.setPrimaryClip(clip);
Toast.makeText(AboutActivity.this,保存到剪贴板,Toast.LENGTH_SHORT).show();
}
ClipData clip = ClipData.newPlainText(
文本标签,
要复制的内容);
此处文本标签描述了剪辑中的数据
例如
ClipData剪辑= ClipData.newPlainText(
用户名,
user.getName()) ;
我们可以使用
<$ p来检索$ p>
clip.getDescription();
According to the Android documentation, ClipData use "label" as a kind of representation to the copied data.
ClippedData is a complex type containing one or Item instances, each of which can hold one or more representations of an item of data. For display to the user, it also has a label and iconic representation.
And then it further explains "label" as User-visible label for the clip data in some API docs. However, I'm still confused about the usage of the label.
How is this label visible to users? How should I use it? What should I set for this label when I call the ClipData factory method newPlainText(CharSequence label, CharSequence text)
? for example:
private void copyToClipBoard() {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(
"text label", // What should I set for this "label"?
"content to be copied");
clipboard.setPrimaryClip(clip);
Toast.makeText(AboutActivity.this, "Saved to clip board", Toast.LENGTH_SHORT).show();
}
ClipData clip = ClipData.newPlainText(
"text label",
"content to be copied");
here text label describes what data is in clip
eg.
ClipData clip = ClipData.newPlainText(
"user Name",
user.getName());
we can retrive this by using
clip.getDescription ();
这篇关于“标签”到底是什么? Android中的ClipData中的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!