Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – Paging3-PagingDataAdapter,How to remove item?

Posted on November 14, 2022

Solution 1 :

The only way to update the backing dataset currently is to call PagingSource.invalidate to trigger another REFRESH, which then reloads from current position via PagingSource.getRefreshKey(state).

e.g.,

val backingDataSet = mutableListOf(1, 2, 3)
class MyPagingSource : PagingSource<Int, Int> {
    override suspend fun load(...) = Page(
        data = backingDataset,
        nextKey = null,
        prevKey = null,
        itemsBefore = 0,
        itemsAfter = 0
    )

    override fun getRefreshKey(state: PagingState<Int, Int>) = state.anchorPosition
}

...

var currentPagingSource: MyPagingSource? = null
val pager = Pager(...) {
    MyPagingSource().also{
        currentPagingSource = it
    }
}

...

// To remove an item
backingDataSet.removeAt(0)
currentPagingSource.invalidate()

Problem :

This question already has answers here:

How to remove an item from PagedListAdapter in Android Paging Component

(2 answers)
How to delete/remove PagedListAdapter item

(4 answers)
How to update single item using Paging 3 library

(3 answers)
Closed 1 year ago.

Android Paging3 alpha03, How to remove or update item?

Help,please

Comments

Comment posted by Freshchris

Hello, please describe your problem more detailed. What exactly did you try? What is your goal? What errors did you encounter? More details help other people to understand your problem better.

Comment posted by sourcediving.com/…

check this article

Comment posted by Florian Walther

Why is this marked as duplicate with questions about Paging 2, which is a completely different library?

Comment posted by Darshana

pagingAdapter.refresh() working for me

Comment posted by mumu

Thanks, Can I specify to refresh the second page data?

Comment posted by dlam

Currently you must invalidate the entire source.

Comment posted by Florian Walther

@dlam What about using

Comment posted by dlam

@FlorianWalther Always invalidate after updates to the backing dataset. Trying to sync local state with paginated backing data is really hard to do correctly and you won’t get help on that path. For example, how will you resolve races between notifyItem and a prepend or a drop? Another hard case is restoring from cached PagingData, you will need to figure out what is presented and re-insert the correct item. SavedState is even more complicated. So I would definitely not recommend to try to be clever by using notify directly.

READ  [ANSWERED] android - Kotlin CameraX can't capture image
Powered by Inline Related Posts

Comment posted by Florian Walther

@dlam Thank you for the input. If I have 500 paginated items on the list a call to

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

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

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress