Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is "label" parameter in ClipData in Android?

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(); } 
like image 425
hackjutsu Avatar asked Oct 19 '15 06:10

hackjutsu


People also ask

What is ClipData item?

android.content.ClipData.Item. Description of a single item in a ClipData. The types than an individual item can currently contain are: Text: a basic string of text. This is actually a CharSequence, so it can be formatted text supported by corresponding Android built-in style spans.

How do you copy text to clipboard on Android?

Highlight the text, long-press the selected text, then choose Copy. Long-press an empty field and select Paste to insert the copied text. Alternative method: Use the Gboard keyboard to manage the clipboard.

How do I use clipboard manager on Android?

One of these is an integrated clipboard manager. Like Gboard and the Samsung Keyboard, just tap the arrow icon in the top-left corner of your keyboard, and you'll see the Clipboard icon, among others. Tap it to access blocks of text you've copied recently, then you can paste them with one tap.


1 Answers

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 (); 
like image 129
Gaurav Avatar answered Sep 19 '22 13:09

Gaurav