java - Button copying text to clipboard -


i trying copy text clipboard when button pressed. have found other questions this, can't figure out code. here code trying use now:

button button = (button)this.findviewbyid(r.id.button1);  clipboardmanager clipboard = (clipboardmanager) getsystemservice(context.clipboard_service); clipdata clip = clipdata.newplaintext("label","woop woop in clipboard"); clipboard.setprimaryclip(clip); 

but confused on how button action.

use button onclicklistener

button.setonclicklistener(new view.onclicklistener() { public void onclick(view v) {     clipboardmanager clipboard = (clipboardmanager) getsystemservice(context.clipboard_service);     clipdata clip = clipdata.newplaintext("label", "woop woop in clipboard");     clipboard.setprimaryclip(clip); }}); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -