android - getSystemService() not working on Adapter Class -
i trying add onclicklistener button inside recyclerview wii copy string says getsystemservice(clipboard_service) not available.
public void onbindviewholder(viewholder holder, int position) { holder.title.settext(carditems.get(position).title); holder.content.settext(carditems.get(position).content); holder.copybutton.setonclicklistener(new view.onclicklistener(){ public void onclick(view v){ myclipboard = (clipboardmanager)getsystemservice(clipboard_service); string text; text = edittext.gettext().tostring(); myclip = clipdata.newplaintext("text", text); myclipboard.setprimaryclip(myclip); toast.maketext(getapplicationcontext(), "text copied", toast.length_short).show(); } }); }
you need context in order that. perform:
... public void onclick(view v) { myclipboard = (clipboardmanager) v.getcontext().getsystemservice(clipboard_service); ... }
Comments
Post a Comment