Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textview textIsSelectable="true" not working in Listview

 <TextView
                    android:id="@+id/txtSender"
                    style="@android:style/TextAppearance.Small"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/sender_bubble"
                    android:gravity="center_vertical"
                    android:maxEms="11"
                    android:paddingBottom="5dp"
                    android:paddingLeft="5dp"
                    android:paddingRight="15dp"
                    android:paddingTop="5dp"
                    android:text="1234567"
                    android:autoLink="all"
                    android:textColor="@color/color_black"
                    android:textIsSelectable="true"
                    android:visibility="visible" />

This is my textview in customcell. When i click on textview it is not allowing me to select the text in textview. It is working perfect in my xperia 4.2.2 but when i run the same code in device having version 4.4.4, it is not working.

NOTE : When i set the same android:textIsSelectable="true" property to the Textview which is not in Listview, it works fine in 4.4.4. Listview just move to bottom and resets to its original position within half of a second.

like image 366
Beena Avatar asked Oct 15 '14 10:10

Beena


2 Answers

In my case it wasn't working because I had textView in xml layout with android:visibility="gone" property and made it visible later in adapter code. So, you need call this after you makes textview visible

textView.setTextIsSelectable(true); 
like image 132
Georgy Gobozov Avatar answered Nov 14 '22 23:11

Georgy Gobozov


Remove android:descendantFocusability="blocksDescendants"​ in the recyclerview or listview to prevent the blocking of selection

Also, change the textview layout width from match_parent to wrap_content to prevent the selectable text feature to be disabled when reusing the text cell.

like image 25
Kit Avatar answered Nov 15 '22 01:11

Kit