Paulo Buchsbaum
Paulo Buchsbaum

Reputation: 2659

How to disable the double click that selects a word in EditText?

In this answer, I've posted my solution for disable default copy, paste, select all and clipboard behaviour for an EditText, including disable handle select cursor:

drop

There are three steps that includes a) a short snippet of code (many times posted in Stackoverflow); b) an empty image and c) a custom and global EditText style

If one does just step a, it keeps on showing the handle select. And if one click the handle select, appears the popup with Clipboard + Select All So one should select an empty image associated with the handle select.

However, there is one feature that I can't handle at all:

The double click Android default behaviour that selects with pink background the clicked word just for a fraction of a second, below showed:

Red Fox

I've tried many solution proposed in StackOverflow, including change onClick (plugged by setOnClickListener) event for disable the TextEdit control for less than 1 second, using timer or post events.

I also tried handle the cursor in onTouch event.

I even try to program a empty double click handling in GestureDetector.SimpleOnGestureListener()

No success. No clue.

Update

For helping clarify, the features of my problem demand:

1) There is no way to display any extra keys to start typing

2) I need to let the user touch any point of the text, indicating their "insert" position, if applicable. Usually he types at the end of the text and there is no cursor. In that case, I disable it.

3) I need to let the user touch in sequence 2 points of the text, to make a selection, with a marked background. It's not exactly a double click, it's two comfortably separate clicks. I don't like double click for mobile.

-/-

In short, I need to work with the cursor, but not in the standard way that Android offers. Therefore I would need to disable the default Android behaviour, but without losing the cursor and the ability to select a piece of text.

-/-

There is an option to make an artificial cursor that blinks, but I imagine it is quite laborious because the cursor don't occupy on character position exactly.

Update 2

When I use in EditText global style

<item name="android:focusableInTouchMode">false</item>

The double click becomes inactive, but I cannot show the cursor anymore neither make a selection by software.

Upvotes: 3

Views: 2982

Answers (2)

Paulo Buchsbaum
Paulo Buchsbaum

Reputation: 2659

I've found a way to work around the problem. It is not the most elegant solution that could exist, however it acceptable.

However, I don't go consider a right solution, it is just a trick. It's amazing that apparently has no general solution to turn off word selection by double click.

When I create the EditText dinamically, i set

tEdit.setHighlightColor(Color.TRANSPARENT)  // tEdit is my TextEdit view

When I will select an area inside my program, I will use underline to delimit my selected area, so I keep the highlight color always transparent.

Upvotes: 0

Blundell
Blundell

Reputation: 76544

Have you tried this:

1) Have a TextView showing on the screen (non editable with non of the problems you are explaining).

2) Have a button on the screen that says "start typing" or whatever you want as UX to start the interaction. You could even put the click listener straight on the TextView.

3) Have an offscreen / hidden under another view EditText, that when the OnClick in #2 is triggered will focus on this view - thus popping up the keyboard and starting input.

4) Have a text changed listener on the edittext and whenever they type into the edittext it updates the TextView from #1 with this text.

Thus making the whole thing cursor-less.

Upvotes: 1

Related Questions