-3
public void onBindViewHolder(@NonNull final holderView holderView, final int position) {
     holderView.insptext.setText(inspirationItemsList.get(position).getName());
     holderView.copy.setImageResource(inspirationItemsList.get(position).getCopy());
     holderView.share.setImageResource(inspirationItemsList.get(position).getShare());



        holderView.copy.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){



                Toast.makeText(v.getContext(), "Copied to clipboard" , Toast.LENGTH_SHORT ).show();

            }
        });
AskNilesh
  • 67,701
  • 16
  • 123
  • 163

2 Answers2

0

If you want to copy to clipboard programatically here is the reference link :

And this is how you implement it :

import android.content.ClipboardManager;
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
ClipData clip = ClipData.newPlainText("label", "Text to copy");
clipboard.setPrimaryClip(clip);

And here is the documentation for the ClipboardManager

coroutineDispatcher
  • 7,718
  • 6
  • 30
  • 58
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/22775916) – Samuel Philipp Apr 17 '19 at 10:30
  • 2
    I am updating the answer here – coroutineDispatcher Apr 17 '19 at 10:30
-1

In order to copy something in your clipboard, use the code below:

ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); 
ClipData clip = ClipData.newPlainText(label, text);
clipboard.setPrimaryClip(clip);
Mohammad Zarei
  • 1,773
  • 14
  • 33