Android Adapter.getViewByPosition 错误:'请先绑定 RecyclerView!'
这个提示通常是因为在调用 adapter.getViewByPosition(position) 方法之前没有给 RecyclerView 绑定适配器,或者适配器不为空。在使用 getViewByPosition 方法之前,需要先确保以下步骤:
- 
给 RecyclerView绑定适配器,例如:recyclerView.setAdapter(adapter);
- 
确保适配器不为空,例如: if (adapter != null) { View view = adapter.getViewByPosition(position); // ... }
如果以上步骤都已经执行,但是仍然出现提示,请检查以下问题:
- 
是否在 getViewByPosition方法之前调用了notifyDataSetChanged方法,导致适配器被重新设置,需要重新绑定适配器。
- 
是否在 getViewByPosition方法之前调用了setLayoutManager方法,没有设置布局管理器,导致适配器无法与RecyclerView绑定。
原文地址: https://www.cveoy.top/t/topic/nyw0 著作权归作者所有。请勿转载和采集!