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.
In the main-parent layout of recyclerview add attribute
android:descendantFocusability="beforeDescendants"
and then in TextView of rowitem layout add
If you add
android:descendantFocusability="blocksDescendants"
in therecyclerview
orlistview
, then remove it. And after check thisAdd In Your RecyclerView Adapter:
its worked for me..
There seems to be many that have problems with this and indications that it may be a bug in the Android code but I don't have a problem. This is what works for me both for an
OnClickListener()
and the native selection popup. (Tested on KitKat 4.4, Lollipop 5.1 and Nougat 7.1)In the adapter
And my item layout