14

"TextView does not support text selection. Action mode cancelled."

I get this error when I try to bring up the context menu in an EditText in a PopupWindow in Android. The selection markers also do not work.

The question has been asked a number of times but has stayed unanswered:

How to enable selection markers for EditText in PopupWindow?

PopupWindow not triggering sytem context dialog on EditText long-press

I am just another person dealing with the same issue. Any ideas?

Community
  • 1
  • 1
rwx
  • 573
  • 1
  • 7
  • 22

6 Answers6

15

I have check around one hour, i found the solution: setwidth = wrapcontent (it's working with me)

hungkk
  • 338
  • 3
  • 11
  • 3
    Yes, it works because the TextView has to layout again. You can trace the `setText` method to understand why. But layout a view is expansive. It's an old bug of Android which google just don't want to fix it. – Kimi Chiu Feb 02 '17 at 08:03
  • 1
    Worked for me on Android 6.0.0! – Evan Dec 04 '17 at 20:59
  • 1
    OMG, you are a life saver! WTF is that bug seriously... they could at least state something in the documentation. – Simon Ninon Jul 12 '18 at 17:51
5

If TextView, have you tried textView.setTextIsSelectable(true); Or if EditText, editText.setSelectAllOnFocus(true);

rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
Yojimbo
  • 23,288
  • 5
  • 44
  • 48
  • Hi Yojimbo, thanks for your reply, it is an EditText that I am dealing with. I tried editText.setSelectAllOnFocus(true) but I get the same error. Originally I had issues bring the keyboard too but I found an answer to that. I needed to make the PopupWindow focusable which I did in the constructor. – rwx Apr 07 '13 at 01:32
  • As EditText extends TextView, the setTextIsSelectable method is also available for it. It did work in my case. SelectAllOnFocus attribute changes the selection mode on click: from placing the cursor in click position (if false), to selecting all provided text (if true). – nluk Jan 25 '20 at 13:09
4

I believe this is an Android bug, and I just reported it as such: https://code.google.com/p/android/issues/detail?id=62508

We will see whether Google agrees.

Adam Kemp
  • 101
  • 6
4

try

et.setTextIsSelectable(true);
et.setFocusable(true);
et.setFocusableInTouchMode(true);
3

Check if you have

android:focusable="false" or

android:focusableInTouchMode="false" in your xml layout.

rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
Reda
  • 1,277
  • 1
  • 13
  • 27
0

I replaced PopupWindow with DialogFragment, that solved my problem. You may try same. Also, I observed DialogFragment is more stable and I recommend it over PopupWindow. I faced multiple issues with PopupWindow, those were fixed when I started using DialogFragment.

I did not set selectAllOnFocus property.

Swaroop
  • 532
  • 1
  • 4
  • 16