1

I am having a disabled Edittext and now i want to give the select and copy functionality on it. is it possible with disabled edittext ?

Zahid Naqvi
  • 536
  • 1
  • 5
  • 18

2 Answers2

1

Pulled from: How to make an EditText selectable but not editable on Android Ice Cream Sandwich?.

If you have API below 11 use the following code in your edittext XML:

android:inputType="none"
android:textIsSelectable="true"

if API is 11 or above use the following java:

edittext.setTextIsSelectable(true);
Community
  • 1
  • 1
frogmanx
  • 2,620
  • 1
  • 18
  • 20
  • I can confirm that on API 10 (tested on 2.3.4 and 2.3.6) the above two lines doesn't work. The EditText is still editable and the keyboard pops out.. – Bruce Nov 24 '13 at 01:24
0

You should use TextView instead of disabled EditText and try android:textIsSelectable.

If you are targetting old API then you can attach a click listener on TextView and in onClick just do:

ClipboardManager cm = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(textView.getText());
Toast.makeText(context, "Copied", Toast.LENGTH_SHORT).show();

and then later somewhere:

String copiedText = cm.getText();

Also for more advanced implementation please read http://developer.android.com/guide/topics/text/copy-paste.html

M-Wajeeh
  • 17,204
  • 10
  • 66
  • 103