RecyclerView 中EditText 长按复制、粘贴问题解决。
问题:
长按文本框无法弹出复制、粘贴框,LogCat 提示:
TextView does not support text selection. Selection cancelled.
解决方法
一:
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
super.onViewAttachedToWindow(holder);
holder.mEditText.setEnabled(false);
holder.mEditText.setEnabled(true);
}
二:
mEditText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
mEditText.setTextIsSelectable(true);
return false;
}
});
添加代码后,长按可弹出复制、粘贴框,但偶现获取焦点后无法弹出输入法
处理办法
mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v,
boolean hasFocus) {
if (v instanceof EditText)
if (hasFocus) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
}
}
});