我在主片段上有一个TextView(sub_text),另一个是RecyclerView
(rv)包含TextView项.
当我尝试在RecyclerView中选择文本时,我获得了不同数量的项目.
它缺少实现ACTION_PROCESS_TEXT的其他应用程序的选择.
我选择的项目只是部分 – 与stackoverflow上的其他问题不同(例如“android:textIsSelectable=”true” not working for TextView in RecyclerView),其中选择完全缺失或不起作用.
如何使rv的textView中的项与片段的textView相同?
在我的TextView上,我得到以下浮动文本选择工具栏
但是,当我尝试从Recycler视图中选择文本时,我得到以下浮动文本选择工具栏
请注意,RV中只有2个可选项?
sub_text的xml是
rv的xml是
rv中textview的xml是
最佳答案
Text View need to be enabled,focusable,longClickable and
textIsSelectable
use bellow recycler view code
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);
}
}