RecyclerView内存在多个EditText时,长按弹不出系统的复制/粘贴/全选等选择

在仿微博发布头条文章功能的时候出现了这么一个问题。

 public class NewsReleaseAdapter3 extends RecyclerView.Adapter {

    private Context context;
    private List<EditDetailBean> list;

    public NewsReleaseAdapter3(Context context, List<EditDetailBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        EditText editText = new EditText(context);
        editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        return new TxtViewHolder(editText);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof TxtViewHolder) {
            setTxtView((TxtViewHolder) holder, position);
        }
    }

    private void setTxtView(TxtViewHolder holder, final int position) {
        final EditDetailBean bean = getItem(position);
        if (bean != null) {
           _ holder.contentEt.setText("123321123");_
        }
    }


    private class TxtViewHolder extends RecyclerView.ViewHolder {

        EditText contentEt;

        private TxtViewHolder(View itemView) {
            super(itemView);
            contentEt = (EditText) itemView;
//            contentEt = (EditText) itemView.findViewById(R.id.contentEt);
        }

    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    private EditDetailBean getItem(int position) {
        return list.get(position);
    }

只要添加了“holder.contentEt.setText("123321123");”经过滑动,就会出现EditText长按没有震动反馈,也没有弹出菜单。但是能进入onLongClickListener.
跪求大神

2个回答

直接上代码,本人测试好用:

holder.reportContent.setOnFocusChangeListener((v, hasFocus) -> {
            if (hasFocus) {
                holder.reportContent.setTextIsSelectable(true);
            } else {
                holder.reportContent.setTextIsSelectable(false);
                holder.reportContent.setFocusableInTouchMode(true);
                holder.reportContent.setFocusable(true);
                holder.reportContent.setClickable(true);
                holder.reportContent.setLongClickable(true);
            }
        });

初步认为是setText覆盖了BufferType,导致弹不出复制粘贴功能,看下BufferType类型,应该是通过SPANNABLE类型来实现选中效果实现复制粘贴

public enum BufferType {
        NORMAL, SPANNABLE, EDITABLE
    }
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问