android - notifyItemInserted() 没有像我预期的那样工作

标签 android

我需要做的是将项目插入到 RecyclerView 的顶部。我有一个适配器,它保留了我的项目的 List,当我想添加到 RecyclerView 的顶部时,我只是使用这段代码:

mItems.add(0, item);
notifyItemInserted(0)

不幸的是,它只是重新加载了 RecyclerView 的最后一项。当然,当我将 notifyItemInserted 更改为 notifyDataSetChanged() 时,一切正常。为什么 notifyItemInserted 不合适?

最佳答案

只需从 RecyclerView 的初始化中删除 setHasFixedSize(true)

关于android - notifyItemInserted() 没有像我预期的那样工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44004812/

相关文章:

android - 这个 Loader 类应该是静态的,否则可能会发生泄漏 |内部类内存泄漏 | AsyncTaskLoader 内存泄漏 -

android - 在 Android 的 TabActivity 中使用 Google Analytics

java - Android:如何使用定时器

android - ImageCatche 中的 NullPointerException

android - 为什么我使用 scroll|enterAlways 在我的 AppBarLayout 上获得额外的 50 像素的 vscrolling?

android - 如何解决 W/art : Could not create image space with image file '/system/framework/boot.art' while trying to port Android Lollipop on Arndale Board?

android - 按住按钮时限速功能

android - 如何创建具有自定义 ID 值的微调器?

android - 如何计算合适的android小部件大小?

android - 如何修复 - "This version of the application is not configured for Market Billing"?