0

When the user long-touches/long-clicks in the EditText, my app always selects all text. How do you instead make the EditText not select all, and instead select only the user-selected text?

I read Select all text inside EditText when it gets focus then tried explicitly setting android:selectAllOnFocus="false"but that is not working. Double tapping or any other click length doesn't work either.

To override OnLongClickListener might work, but I don't know how to get the user's start and end selected index.

Community
  • 1
  • 1
T. Webster
  • 9,605
  • 6
  • 67
  • 94

2 Answers2

1

For those who are coming across this question in the future, the (or at least a) solution is to add the textLongMessage option to android:inputType:

<EditText
    ...
    android:inputType="textLongMessage" >

<!-- Or you might have multiple input types -->
<EditText
    ...
    android:inputType="textLongMessage|textMultiLine|textNoSuggestions" >

This will make the EditText's behavior be to select a single word from the text.

Unlocked
  • 648
  • 6
  • 19
-2

Try reading these liknks and see if they help: how to NOT select all on EditText long click

how to NOT select all on EditText long click

You can try in your main.xml file:

android:selectAllOnFocus="true"
Community
  • 1
  • 1
node
  • 90
  • 3