Comments (4)
Look a bit further in the error message. One part of the issue actually originates from the problem that your ModelAdapter
does not have a proper generic type specification: ModelAdapter<Any, Nothing>
The generic type should resolve to: <Model, Item : GenericItem>
with GenericItem
being a typealias for IItem<out RecyclerView.ViewHolder>
What you want to do is to ensure the generic type for the adapter is properly defined.
The other issues results from the classes not having a common base interface or similar. In detail this also results from generics, but you can work around this easily by introducing a common interface. Somewhat like:
{
val itemAdapter = ModelAdapter<X, GenericItem> { element: Any ->
if (element is Avatar) {
AvatarItem(element)
} else if (element is User) {
UserItem(element)
}
throw IllegalArgumentException()
}
val fastAdapter = FastAdapter.with(listOf(itemAdapter))
val models = ArrayList<X>()
for (i in 0 until nextInt(0, 100)) {
if (i % 3 == 0) {
models.add(User())
} else {
models.add(Avatar())
}
}
itemAdapter.add(models)
}
interface X
class Avatar(): X
class User(): X
class AvatarItem(val avatar: Avatar): AbstractItem<RecyclerView.ViewHolder>() {
override val type: Int
get() = TODO("Not yet implemented")
override val layoutRes: Int
get() = TODO("Not yet implemented")
override fun getViewHolder(v: View): RecyclerView.ViewHolder {
TODO("Not yet implemented")
}
}
class UserItem(val user: User): AbstractItem<RecyclerView.ViewHolder>() {
override val type: Int
get() = TODO("Not yet implemented")
override val layoutRes: Int
get() = TODO("Not yet implemented")
override fun getViewHolder(v: View): RecyclerView.ViewHolder {
TODO("Not yet implemented")
}
}
from fastadapter.
I know the cause of the problem, there is duplication of method signatures because of generic erasure.
I wanted to express that when there is no association between two data classes, it is not possible to use entries of multiple types.
from fastadapter.
I am not sure if this can be resolved due to how generics work. If you have proposals I'd love to hear about them.
In any case as outlined above, you can always introduce an interface adding a common interface between your classes.
from fastadapter.
Closing due to inactivity
from fastadapter.
Related Issues (20)
- compile error HOT 2
- CreateBinding is being called each time item is being collapsed or expanded. HOT 8
- Setting a Snackbar using UndoHelper's withSnackbar does nothing.
- List is not updating after adapter.set()
- Second added item is blank HOT 6
- SelectExtensions.select() not working when create view HOT 2
- Is there any way to add multiple row? HOT 5
- How made dynamic model list? HOT 6
- How can I judge the item is the last one in AbstractBindingItem HOT 1
- EventHook + RecycledViewPool HOT 3
- How to get access to function of Item from ViewHolder? HOT 4
- ItemFilter publishResults NPE HOT 1
- FastAdapter intercepting clicks for other ViewPager tabs HOT 1
- <table data-meta="generated_by_danger-pr">
- Drag & drop - animation is broken HOT 1
- could not resolve FastItemAdapter , FooterAdapter, ProgressItem HOT 3
- Weird behavior on scroll with expandable HOT 2
- Runtime layout changes can affect more than one item HOT 5
- Can I Swipe item view then remain it's state then delete button can click HOT 2
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 fastadapter.