Creating Models From ViewHolders works in Java. Not in Kotlin
See original GitHub issueI’ve been doing the following when creating Models from viewholders in java
@EpoxyModelClass(layout = R.layout.da_thing)
public abstract class MyModel extends EpoxyModelWithHolder<MyModel.MyHolder> {
@EpoxyAttribute
EmailItem emailItem;
@Override
public void bind(YourViewHolder holder) {
super.bind(holder);
holder.bindingTime(emailItem);
}
static class MyHolder extends BaseEpoxyHolder {
@BindView(R.id.text) TextView textView;
public void bindingTime(EmailItem emailItem) {
textView(your_info_needed_for_model+"");
}
}
}
This works well, but when I convert to Kotlin (kotlin noob here) I get the following. It seems like the fault is mostly on Butterknife. The question is… since using Kotlin I do not use Butterknife anymore.
Essentially I got this though.
@EpoxyModelClass(layout = R.layout.da_thing)
abstract class MyModel : EpoxyModelWithHolder<MyModel.MyHolder>() {
@EpoxyAttribute
var emailItem: EmailItem = EmailItem()
override fun bind(holder: MyHolder?) {
super.bind(holder)
holder!!.bindTo(emailItem)
}
class MyHolder : BaseEpoxyHolder() {
@BindView(R.id.text) var textView: TextView? = null
fun bindTo(emailItem: EmailItem) {
textView?.setText("asdf")
}
}
}
It’d be great to get rid of butterknife in this case. Thoughts @elihart ?
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
How to create RecyclerView with multiple view types
Yes, it's possible. Just implement getItemViewType(), and take care of the viewType parameter in onCreateViewHolder() . So you do something like:
Read more >Using the RecyclerView | CodePath Android Cliffnotes
In this case, we will define a Contact class which represents the data model being displayed by the RecyclerView: Java; Kotlin. public class...
Read more >Create dynamic lists with RecyclerView - Android Developers
These two classes work together to define how your data is displayed. The ViewHolder is a wrapper around a View that contains the...
Read more >Mixing Java and Kotlin in one project – tutorial
You can now consume the Java class from Kotlin or vice versa without any further actions. For example, adding the following Java class:...
Read more >Writing Better Adapters - ProAndroidDev
Creating the view and the ViewHolder that holds the view information. ... kind of objects (this article uses Kotlin but it can be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
changing from
annotationProcessor
tokapt
is the correct fix. I’m guessing you just needed to do a clean build to force it to recompile@ColtonIdle Yes, you can shorten it to something like this
I took some time to write up kotlin samples in a new wiki page https://github.com/airbnb/epoxy/wiki/Kotlin-Model-Examples
I also played around with imagining a completely new kotlin pattern. I think this has potential, but could use some iteration, and possibly some changes to the processor to support it officially.