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 the Android studio template to generate boilerplate code for various RecyclerView styles and designs.

RecyclerViewTemplate

How RecyclerViewTemplate can be useful?

The RecyclerView is the most common view that we 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 ease by just entering and checking the fields in the wizard. (No coding skills required :))

Behind the scenes?

RecyclerViewTemplate primarily uses Textfield, Spinner, and Checkboxes for UI presentation. Please refer to my previous article if you are not familiar with Android Studio Template UI creation https://medium.com/androidstarters/mastering-android-studio-templates-ed8fdd98cb78

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 an 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
         SHOW_FRAGMENT_UI;
}else{ //If Need Fragment code instead of Activity is unchecked
         SHOW_ACTIVITY_UI;
}

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 the following expression

Where,

${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 edit text.getText().toString() in Android.

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

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

item_recycler_list.xml.ftl

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

RecyclerViewTemplate Styles and Types:

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

RecyclerViewTemplate — One Template which solves all frequently used RecyclerViews Code Snippetsgithub.com

MaterialTabsTemplate is solely created to reduce the burden of writing same boiler plate codes for Tab creation in…*github.com

Introducing AndroidStarters

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.