First of all, this is my first blog post, so here is a quick intro. I’m will try to share some interesting blog posts about cool things that I know.
We all hate (or at least I do) writing boilerplate code so I would like to share this quick way for writing RecyclerView Adapter. Before we create an adapter, we need to prepare 2 simple things; one is a class that will be our model, and second will be a layout for an item in the RecyclerView.
Now go to Android Studio > Preferences > Editor > File and code templates and click on that “+” icon for adding the new one.
You may notice that I use ButterKnife library, but you don’t have to, but you should 🙂
Now that we are all set, we need to finally create that adapter. Go to the File > New > and select your RecyclerView adapter template.
You will see a dialog like this, fill name for you adapter class, item class, and finally your item layout, click OK and… magic. The boring part of your adapter class is already written, all you have to do is make sure that you Inject your views and fill it with data (the fun part).