1

I'm new to Android. I want to display the copied coupon code.

Here is code:

ClipboardManager clipboard = (ClipboardManager) mCtx.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Code", artist.getCoupon_code());
clipboard.setPrimaryClip(clip);
Toast.makeText(mCtx, "coupon code: "+clip+" is copied" , Toast.LENGTH_SHORT).show();

How to remove the red-underlined text and only display the coupon code i.e. green underlined text.

output:
output

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ashish
  • 75
  • 7

2 Answers2

1

The string you want may be found in

clip.getItemAt(0).getText();

or

clipboard.getPrimaryClip().getItemAt(0).getText();

or, because you are setting the clip right there, you can just use the value directly, in the string

artist.getCoupon_code()

Good luck!

Brandon Xia
  • 407
  • 3
  • 19
1

The snippet below should do the tric for you.

ClipboardManager clipboard = (ClipboardManager) mCtx.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
Toast.makeText(mCtx, "coupon code: "+item.getText()+" is copied" , Toast.LENGTH_SHORT).show();

Find more info about copying and pasting from the link below.

Copy and Paste | Android developers

Piper2
  • 299
  • 2
  • 10