-
Copying Text from Listview
about 9 years ago
-
about 9 years ago
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(); }
-
1 Answer(s)