Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

 1 Answer(s)

  • To copy any string to clipboard we need to check the sdk version as it is different for the sdks that are below the HONEYCOMB and that are above HONEYCOMB

        
    TextView contentTextBox=(TextView) view.findViewById(R.id.tv_content); //get textview of listview from which you want to copy the content
        String textToCopy = contentTextBox.getText().toString();
          if(textToCopy.length() != 0)
            {
               if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) // check sdk version
                  {
                     android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                     clipboard.setText(textToCopy);
                     Toast.makeText(getApplicationContext(), "Copied to Clipboard", Toast.LENGTH_SHORT).show();
                  }
               else 
                  {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemServic(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clipData = android.content.ClipData.newPlainText("Clip",textToCopy);
                    Toast.makeText(getApplicationContext(), "Copied to Clipboard", Toast.LENGTH_SHORT).show();
                    clipboard.setPrimaryClip(clipData);
                   }
            }
           else
             {
              Toast.makeText(getApplicationContext(), "Empty Selection", Toast.LENGTH_SHORT).show();
             }
    
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: