Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – ListAdapter, update items like notifyDataSetChange

Posted on November 11, 2022 By

Solution 1 :

You can save the scroll position prior to calling submitList() and then restore it afterwards:

https://stackoverflow.com/a/32526482/7434090

Solution 2 :

Yes, It is possible to update Adapter items in a way that doesn’t refresh the whole list. Suppose you created an adapter and the name of the adapter is “ListAdapter“.If you wanna update the adapter items that means you wanna change the value of a certain position. Here you just pass the position.

listAdapter.notifyItemChanged(position:Int)

Maybe you inserted values in a position,

listAdapter.notifyItemInserted(position:Int)

or you may remove a value from a position,

listAdapter.notifyItemRemoved(position:Int)

Solution 3 :

As ianhanniballake mentioned, I was implementing the DiffUtil incorrectly. I was checking the whole new and old values in areItemsTheSame function, while should only check a unique field (like id).

    override fun areItemsTheSame(oldItem: FuelSubsidyEntity, newItem: FuelSubsidyEntity): Boolean {
        return oldItem.reportId == newItem.reportId
    }

Problem :

Is there any way to update ListAdapter items in a way that doesn’t refresh the whole list?
For now, if you call adapter.submitList(newITems) again, it will scroll the list to the top again, not just replacing current items with new ones.

Comments

Comment posted by ianhanniballake

Clearly you have not implemented DiffUtil correctly, otherwise RecyclerView would have kept the topmost visible item with a matching ID visible. Include your class and your DiffUtil implementation.

READ  [FIXED] java - Perform an Action when phone is shaked
Powered by Inline Related Posts
Android Tags:android, android-recyclerview, listadapter

Post navigation

Previous Post: [FIXED] android – Overlapping items in RelativeLayout with ImageView and TextView
Next Post: [FIXED] android – Unable to instantiate application com.company.app.MainApplication: java.lang.ClassNotFoundException React Native Expo

Related Posts

[FIXED] android – Cannot Select Item in Navigation Drawer Android
[FIXED] Why do we need to add @SuppressLint(“SetTextI18n”) annotation before concatenating strings in Android Studio Android
[FIXED] How to integrate blockchain contracts mentioned in ABI file to android app? Android
[FIXED] Android Room SQL Query – How can I run a query with a conditional WHERE clause Android
[FIXED] android – Firebase remote config instant localization after language change on app Android
[FIXED] java – /data/local/tmp/test error=13, Permission denied Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme