TextIsSelectable () has missing elements in the floating text selection toolbar for TextViews in recyclerView

I have one TextView (sub_text) on the main snippet and another RecyclerView (rv) containing TextView elements.

I get different amounts of elements when I try to select text in a RecyclerView. There is no choice from other applications that implement ACTION_PROCESS_TEXT.

My selected items are only partial - unlike other stackoverflow questions (for example, "android: textIsSelectable =" true "doesn't work for TextView in RecyclerView ), where the selection is completely missing or doesn't work.

How to make elements in rv text element be the same as textView fragment?

in my TextView, I get a toolbar for selecting floating text

enter image description here

However, when I try to select text from the Recycler view, I get the following floating text selection toolbar

enter image description here

Please note that in RV there are only 2 selectable items?

xml for sub_text

<TextView
    android:id="@+id/sub_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" 
    android:textSize="16sp" 
    android:padding="8dp"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:textColor="@color/primary"
    android:textIsSelectable="true"
    android:visibility="gone" />

xml for rv is

    <android.support.v7.widget.RecyclerView 
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:scrollbars="vertical"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

xml for text view inside rv

 <TextView 
        android:id="@+id/tv_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="4dp"
        android:text="经" 
        android:textColor="@color/primary_dark"
        android:textIsSelectable="true" />
+6
source share
1 answer

The text view should be included, focused, longClickable and textIsSelectable

    <TextView
                android:id="@+id/textViewHeading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:enabled="true"
                android:textIsSelectable="true"
                android:focusable="true"
                android:longClickable="true" />

use the following recycler view code

    <android.support.v7.widget.RecyclerView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:id="@+id/recyclerViewRecordList"
        app:layout_constraintTop_toBottomOf="@+id/relativeLayoutHeader"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/view_bottom"
        android:layout_margin="10dp"
        android:focusable="true"
        android:focusableInTouchMode="true">
    </android.support.v7.widget.RecyclerView>

use SpeedyLinearLayoutManager in code instead of xml

SpeedyLinearLayoutManager linearLayoutManager = new SpeedyLinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
myRecyclerViewList.setLayoutManager(linearLayoutManager);
RecordAdapter myCustomerAdapter = new RecordAdapter(this, myRecordListData);
myRecyclerViewList.setAdapter(myCustomerAdapter);


public class SpeedyLinearLayoutManager extends LinearLayoutManager {

        private static final float MILLISECONDS_PER_INCH = 2f; //default is 25f (bigger = slower)

        public SpeedyLinearLayoutManager(Context context) {
            super(context);
        }

        public SpeedyLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
            super(context, orientation, reverseLayout);
        }

        public SpeedyLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }

        @Override
        public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {

            final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return SpeedyLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
                }

                @Override
                protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                    return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
                }
            };

            linearSmoothScroller.setTargetPosition(position);
            startSmoothScroll(linearSmoothScroller);
        }
    }
+3
source

All Articles