I'm letting the user long click on a TextView
and that will copy the text of the TextView
to their Clipboard
.
I want it so that before it will actually copy the text of the TextView
to their Clipboard
, it will check if the last Clip
on their Clipboard
is the different than the text.
Here is the code:
ClipboardManager clipboard =(ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
String text = textView.getText().toString();
if ( !(clipboard.getPrimaryClip().toString().equals(text)) )
// if ( !(clipboard.getPrimaryClip().equals(text)) )
{
clipboard.setPrimaryClip(ClipData.newPlainText("newClipName", text));
Toast.makeText(getApplicationContext(),"Copied to clipboard.", 0).show();
}
I can only imagine that the method getPrimaryClip()
is not returning a String
and toString()
also doesn't work. How can I get the most recent Clip
as a String
?