Giter Club home page Giter Club logo

Comments (4)

idanatz avatar idanatz commented on June 8, 2024

Hi, Regarding your questions:

It is not working probably because a line after the clear you are adding items to the adapter, thus clearing the empty module and inserting an item module.
why are you calling clear on each observation callback? when using observation with a full item list, it is best to use setItems() and let the adapter calculate the difference between the old and the new list automatically.
if the list is empty, the empty module will be invoked, if not the adapter will render the changes.
no need to call clear, or add in this case.

The itemcount variable is used by the internals of the adapter, it may hold more items than you think to support various functions.
Adding a function the will return the number of items per type (let's say a T model) will be helpful?

First, try what I wrote in question 1 and see if the issue is resolved.
Else, From your code, the id looks fine but there is a setId() function that I don't know if you calling from outside.
The exception means 2 models have the same ID, are you 100% that's not the case?

from oneadapter.

Minification avatar Minification commented on June 8, 2024

Hi, thanks for your reply.

  1. I only added the call to clear() because for some reason I can see more items displayed than I added as can be seen in the screenshot I provided (there are 5 items visible but only 3 should be there (because of the call to clear)).

  2. I see. I only added the output line to check how many items are in the adapter because the logics didn't add up with the visuals.

  3. I removed the call to clear and printed the ids of the items to be added to the console. Every id in the output is unique, which is why I don't understand why the exception would occur. With the clear() removed, the output is as follows, where each output block is what is printed in the observation callback:

CreateMarkerDialogKotlin$onActivityCreated: item id is 1
...
CreateMarkerDialogKotlin$onActivityCreated: item id is 1
CreateMarkerDialogKotlin$onActivityCreated: item id is 2
...
CreateMarkerDialogKotlin$onActivityCreated: item id is 1
CreateMarkerDialogKotlin$onActivityCreated: item id is 2
CreateMarkerDialogKotlin$onActivityCreated: item id is 3

from oneadapter.

idanatz avatar idanatz commented on June 8, 2024

And when you get these logs and crash, are you using add() or setItems()?

Because add() will result in the behavior you are describing and it's intended by design.
The items will be added to the previous items, resulting in more and more items, plus the ids are the same since id=1 for example, is inserted 3 times.
setItems() will compute a diff between the current list and the new list and send updates only when needed.

from oneadapter.

Minification avatar Minification commented on June 8, 2024

I see now, that is why those problems arise. I didn't know add() behaved like this by design (I thought it handled the diff calculation and setItems was just a setter).

With that knowledge, I'm closing the issue of course, though unless I missed it, I feel the documentation should include this rather important detail.

Come to think of it, I don't even know why I used add() instead of setItems()...

Thanks for your help, this definitely restores my faith in this library.

from oneadapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.