Bug总结
After EditText
正在被回收RecyclerView
,其用于选择所有文本并显示上下文菜单“剪切/复制/粘贴”的长按行为不再按预期工作。
从 Android 15 到 Android 28 都会出现此问题。
我都尝试过EditText
and android.support.v7.widget.AppCompatEditText
。两者都会产生同样的问题。
我可以确认此问题发生后View
正在被回收。如果我申请setIsRecyclable(false);
in ViewHolder
,则不会出现该问题。
重现步骤
- 长按1号
EditText
。我们可以确认所有文本EditText
将被选中。将显示上下文菜单。
- Scroll
RecyclerView
直到列表末尾。
- Scroll
RecyclerView
直到列表的开头。
- 长按1号
EditText
。所有文字都在EditText
不会被选中。将不会显示上下文菜单。
预期行为
视图被回收后,我们期望步骤 4 的行为仍然与步骤 1 完全相同。
源代码
https://github.com/yccheok/edittext_bug_in_android9 https://github.com/yccheok/edittext_bug_in_android9
问题跟踪器
https://issuetracker.google.com/issues/125425940 https://issuetracker.google.com/issues/125425940
我想知道,有人遇到和我一样的问题吗?您对此有什么好的解决方法吗?请注意,我需要我的RecyclerView
物品可回收。因此,使用setIsRecyclable(false);
对我来说不是一个选择。
简而言之,问题的发生是因为EditText
不执行Editor#prepareCursorControllers
during attachToWindow
.
Since Editor#prepareCursorControllers
不是公共可访问函数,我们可以使用间接调用它setCursorVisible
.
edtImgDesc.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
edtImgDesc.setCursorVisible(false);
edtImgDesc.setCursorVisible(true);
}
@Override
public void onViewDetachedFromWindow(View v) {
}
});
参考来源:https://www.jianshu.com/p/e334134a4ef7 https://www.jianshu.com/p/e334134a4ef7(博客为中文)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)