Creating Android studio IDE Template for RecyclerView’s

Why RecyclerViewTemplate?

I am an Android techie geek who loves to get things done in an elegant, standard and simple way like carving butter. As an early initiative, I thought of automating the workflow and tasks in Android since I realized that I have been doing repetitive tasks all these days. So here comes this Android studio template to generate boilerplate code for various RecyclerView styles and designs.

How RecyclerViewTemplate can be useful?

The RecyclerView is the most common View where we developers will often be using either as a form of Grid, list, headers, footer, sections, horizontal ScrollView, toggle, checkbox and radio lists. So this repo helps to generate boilerplate code with an ease by just entering and checking the fields in the wizard. (No coding skills required :-))

Behind the scenes?

RecyclerViewTemplate primarily uses Textfield, Spinner, Checkboxes for UI presentation. Please refer my previous article if you are not familiar with Android Studio Template UI creation

It’s time to check core logic and template window structure.

  1. How to achieve toggle behaviour similar to the UI shown below?

The below code snippet is used to create Need Fragment code instead of Activity? CheckBox UI component.

Next comes changing the state of TextField based on isFragment logic. Let’s take Activity Name and Fragment Class Name as a example.

Activity Name

Fragment Class Name

Let’s break this into simple logic as follows:

if(isFragment){ //If Need Fragment code instead of Activity is checked
}else{ //If Need Fragment code instead of Activity is unchecked

2. How code generation works based on isFragment true/false states?

This can be achieved through simple if-else logic from a recipes.xml.ftl file using following expression


${className} = Fragment Class Name entered in the text field

${activityClass} = Activity Name entered in the text field

(i.e) ${YOUR_TEXTFIELD_ID} gets the value from text field similar to the behavior of edittext.getText().toString() in Android.

How to load exact layouts and java class files according to user selected option?

Let’s see how adapter layouts are handled for different styles


Similarly, the layout manager behavior can be handled through following checks in or classes as stated below

RecyclerViewTemplate Styles and Types:

Below are the possible RecyclerView designs and styles that can be generated using RecyclerViewTemplate.

Recommended Reading

If you liked this post, hit the 👏 . Stay tuned for the next one!

Also share AndroidStarters and give us some feedback in the comments below.