22

I have a ListView in Activity, and in each item , I insert an EditText for show my text. I need drag the handle to select text & copy the text, but can not edit text. On Android ICS, How can I do this?

izstas
  • 5,004
  • 3
  • 42
  • 56
Limp
  • 319
  • 1
  • 2
  • 8

4 Answers4

23

text.setTextIsSelectable(true) requires API 11. For those using lower API's: In xml use:

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

This will make your EditText uneditable but selectable.

Community
  • 1
  • 1
Frozen Crayon
  • 5,172
  • 8
  • 36
  • 71
  • 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:25
  • Then what is the solution? – Frozen Crayon Nov 25 '13 at 02:14
  • 1
    Check out my full answer posted at http://stackoverflow.com/a/20173020/1241783. Not very proud of the hacky way but it is the only way that I know of for now. Do let me know if someone knows a better way for API version < 10. Thanks! – Bruce Nov 25 '13 at 14:36
5

I think you could override the onKeyDown() method, make it do nothing but return true. It should catch the keypresses from the keyboard and negate them before they can go into the text in the EditText.

You might also try setting editable to false like this

android:editable="false"

on the EditText in your xml layout. However I am not certain if this will let you still highlight and copy, but it is worth a shot.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
3

I resolved this problem.
Just set TextView like this:

text.setTextIsSelectable(true);
Limp
  • 319
  • 1
  • 2
  • 8
2

Althouth android:editable is deprecated and Lint suggests to use inputType, It doesn't seem to work. So android:editable="false"is apparently the best possible solution for all android versions.

<EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:editable="false"
    android:textIsSelectable="true"
    tools:ignore="Deprecated" />
Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59