Code example for ClipData

0
        String text = "» " + name + ": " + body + "»" + "\n";
 
        ClipData.Item item = new ClipData.Item(text);
 
        String[] mimes = {"text/plain"};
        ClipData dragData = new ClipData(text, mimes, item);
        View.DragShadowBuilder myShadow = new MyDragShadowBuilder(view);
        view.startDrag(dragData, myShadow, null, 0);
 
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(dragData);
        Toast.makeText(context, "Message is copied", Toast.LENGTH_SHORT).show();
        return true; 
    } 
 
    private class MyDragShadowBuilder extends View.DragShadowBuilder {
        private Drawable shadow;
 
        public MyDragShadowBuilder(View v) {
            super(v);
            Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(),Bitmap.Config.ARGB_8888);