Android RecyclerView适配器ViewHolder id有时为-1
我正在使用Recyclerview显示图像和其他内容的列表。当recyclerview加载并快速滚动时,它将崩溃 当我调试时,我可以看到这一点Android RecyclerView适配器ViewHolder id有时为-1,android,android-recyclerview,Android,Android Recyclerview,我正在使用Recyclerview显示图像和其他内容的列表。当recyclerview加载并快速滚动时,它将崩溃 当我调试时,我可以看到这一点 public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { ... viewHolder.getItemId() // this returns -1, sometimes 我怀疑Recyclerview适配器视图未完全创建,对此有何建议?由于您尚未共
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
...
viewHolder.getItemId() // this returns -1, sometimes
我怀疑Recyclerview适配器视图未完全创建,对此有何建议?由于您尚未共享代码,我们不确定您的情况,但让我分享一个可能是您的情况的可能情况。 RecyclerView崩溃的可能案例:
1. This crash might be caused by the fact that the setViewHolder and onBind
methods are being called while your list(used by the adapter) is being updated, but notifyDataSetChanged() hasn't been called.
2. This problem may caused when android start dealing with bitmaps. the main
reason is lack of memory space and also, garbage collector cannot free some
space.
3. If you using image , please confirm the image size because the size may
cause this problem. Some case recyclerview was not able to hold the images
with big resolution.
4. Double check if you are using all the data loading process in ( main/UI
thread ), it my testing Looper.getMainLooper() == Looper.myLooper().
由于您没有共享代码,我们不确定您的案例是什么,但让我来分享一个可能是您的案例。 RecyclerView崩溃的可能案例:
1. This crash might be caused by the fact that the setViewHolder and onBind
methods are being called while your list(used by the adapter) is being updated, but notifyDataSetChanged() hasn't been called.
2. This problem may caused when android start dealing with bitmaps. the main
reason is lack of memory space and also, garbage collector cannot free some
space.
3. If you using image , please confirm the image size because the size may
cause this problem. Some case recyclerview was not able to hold the images
with big resolution.
4. Double check if you are using all the data loading process in ( main/UI
thread ), it my testing Looper.getMainLooper() == Looper.myLooper().
你想达到什么目标?请显示其余的适配器代码。您试图实现什么?请显示适配器代码的其余部分。