Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"android:textIsSelectable="true" not working for TextView in RecyclerView

I know that setting android:textIsSelectable="true" in xml for the TextView will show the native text selection popup and I've been using that in my application. But what I found that it is not working any more when I try to set the same attribute in a view attached to the RecyclerView. Whenever I try to select the text the following log appears -

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

And I don't know why? Why it works on other screens and not with the RecyclerView. I read multiple posts -

TextView with android:textIsSelectable="true" not working in listview

textview textIsSelectable="true" not working in Listview

android:textIsSelectable="true" for TextView inside Listview does not work

But then I encountered this post -

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

And the reply by @hungkk worked for me. His solution suggested the TextView width to change to wrap_content from match_parent.

I know I can do this but my question is how this fixed the issue because it looks weird to me. And also, what is the solution if I want to keep the width to match_parent.

Any inputs are welcome.

like image 301
Shadab Ansari Avatar asked Apr 22 '16 19:04

Shadab Ansari


1 Answers

In the main-parent layout of recyclerview add attribute

android:descendantFocusability="beforeDescendants"

and then in TextView of rowitem layout add

android:textIsSelectable="true" 
like image 70
Nitin Patel Avatar answered Sep 28 '22 03:09

Nitin Patel