在 RecyclerView 中获得负面位置

Mor*_*hin -1 java android android-recyclerview

为什么有时负数返回 RecyclerView 中的位置?

获取位置:

holder.getAdapterPosition()
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 5

来自官方文档

请注意,如果您已调用notifyDataSetChanged(),则在下一次布局传递之前,此方法的返回值将为NO_POSITION

返回项的适配器位置,如果它仍然存在于适配器中。NO_POSITION如果 item 已从适配器中删除、notifyDataSetChanged()在最后一次布局传递后已被调用或ViewHolder已被回收。

NO_POSITION 值为 -1。