Comments (4)
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.
Hi, thanks for your reply.
-
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)).
-
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.
-
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.
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.
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)
- Support for StateRestorationPolicy HOT 4
- Scroll to first added element HOT 7
- Random crash in onCreate HOT 3
- use setItem, but the onBind method not be invoke HOT 12
- Question:Paging with Room Datasource HOT 2
- IndexOutOfBoundsException: Inconsistency detected HOT 2
- CalledFromWrongThreadException in 2.1.0 HOT 9
- Add drag & drop support
- Multiple ViewType HOT 9
- Can we call next page with Paging Module to load without scrolling HOT 5
- Preselected Items HOT 1
- Load more animation when submit empty list HOT 1
- It not a function to get the data from adapter. HOT 1
- Retry button HOT 2
- View Binding with Kotlin 1.6.0 not working HOT 5
- How do i filter the list ?
- You can't use interface as M : Diffable in intem module HOT 1
- select all
- Dynamic layout manager
- Multiple Selection Cancellation Issue When Item Is Not Visible
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oneadapter.