New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overload resolution ambiguity with adapter(RenderableArrayAdapter) #14
Comments
@corbt Thanks for trying Anvil and for reporting this. There is nothing wrong with your code, and your assumption about the adapters type hierarchy is absolutely correct. Since Attrs.java code is generated from android.jar it doesn't notice that ListAdapter, SpinnerAdapter and just Adapter are inherited, so it generates 3 separate functions for adapter() binding. In java I currently cast the class like |
Ok, makes sense. That workaround will work fine for now. For anyone using Kotlin, here's how I cast the adapter to make that work: var testAdapter = object: RenderableArrayAdapter<String>(testNames) {
override fun itemView(i: Int, t: String?): Nodes.ViewNode? {
println("rendered a list item")
return v<TextView> { - text(t) }
}
}
...
v<ListView> {
- adapter(testAdapter: ListAdapter)
} |
I have to warn you about the main caveat of Anvil. Inside your This means that if you keep a reference to your adapter in your activity - it will be created once, and on each render cycle no extra actions will happen, because the same adapter is reused in each rendering cycle. However, if you call it like Rendering cycles do not happen too often, they happen every time the on...Listener callback is called with any of your views (e.g. on every user interaction). But it can slow down your app significantly if you handle scrolls, drags, touches or other "frequent" events. On the other hand, I personally find it appropriate to write |
Now back to the original question, I think we can safely remove I'm still looking at ExpandableList, which uses two setAdapter() methods, and the one with ListAdapter throws a runtime exception. That's a bummer. |
@corbt You may fetch Anvil from tip and try it with your sources. I've just pushed the fixed generated Attrs.java, so now no type cast it needed. It should work for all AdapterViews (List, Spinner, Grid), and for ExpandableAdapterView as well. |
After an extended weekend I'm back at it. It looks like that change fixed the issue, at least for my very simple test case. The only thing to note is that I had to switch my import from |
v10 is for API level >= 10 (Android 2.3.3, 99% of the devices) |
Makes sense. With the new code push v15 is working again, so I've switched back to that because it's lower than the API level I'm supporting anyway. |
This has been fixed for both v10 and v15, so I'm closing the issue |
* add sample for constraint dsl * remove unnecessary DSL prefixes
I have the following test activity in kotlin that is causing an error that appears to be related to the implementation of
RenderableArrayAdapter
:The compiler throws the following error for the
adapter()
function call:It looks like this is because RenderableArrayAdapter implements ListAdapter and SpinnerAdapter (and I guess Adapter as well). But since there are different implementation bodies the method doesn't resolve. Is there something I'm doing wrong here, or should
adapter
be combined into a single method call that dispatches internally based on its argument type?The text was updated successfully, but these errors were encountered: