Creating Android studio IDE Template for RecyclerView’s
Tags: plugins, android, androiddevelopment, androiddev
Published: 2023-01-06 17:43:09

---
title: Creating Android studio IDE Template for RecyclerView’s
published: true
date: 2017-10-17 17:25:46 UTC
tags: plugins,android,androiddevelopment,androiddev
canonical_url: 
---

 **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.

[TakeoffAndroid/RecyclerViewTemplate](https://github.com/TakeoffAndroid/RecyclerViewTemplate)

**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 :-))

{% youtube 75HLkuolGeY %}

**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 [https://medium.com/androidstarters/mastering-android-studio-templates-ed8fdd98cb78](https://dev.to/chandrudotxyz/mastering-android-studio-templates-creation-21oe-temp-slug-7982434)

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

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

![](https://cdn-images-1.medium.com/max/1024/1*uKBRjqYXRAqB2JihZbQFOg.gif)

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

<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c197f896ed30c4f56c40de7bccc78cf/href">https://medium.com/media/7c197f896ed30c4f56c40de7bccc78cf/href</a></iframe>

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**

<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27d4798007fd0c681a67a36c9ada6a49/href">https://medium.com/media/27d4798007fd0c681a67a36c9ada6a49/href</a></iframe>

**Fragment Class Name**

<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46d9807f2abbab39b6337c434448330d/href">https://medium.com/media/46d9807f2abbab39b6337c434448330d/href</a></iframe>

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

<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd471d4894615bb9cb79772240e17fcb/href">https://medium.com/media/bd471d4894615bb9cb79772240e17fcb/href</a></iframe>

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 **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

**item\_recycler\_list.xml.ftl**

<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7284c6bd9f07b86113b3c8f9834cb690/href">https://medium.com/media/7284c6bd9f07b86113b3c8f9834cb690/href</a></iframe>

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

<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/104f4f82ab23a0b1ca5b4773d4db6acf/href">https://medium.com/media/104f4f82ab23a0b1ca5b4773d4db6acf/href</a></iframe>

RecyclerViewTemplate Styles and Types:

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

<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e4f748404ec110b5b1098fb2a912f95/href">https://medium.com/media/0e4f748404ec110b5b1098fb2a912f95/href</a></iframe>
- [TakeoffAndroid/RecyclerViewTemplate](https://github.com/TakeoffAndroid/RecyclerViewTemplate)
- [TakeoffAndroid/MaterialTabsTemplate](https://github.com/TakeoffAndroid/MaterialTabsTemplate)

### Recommended Reading

[Introducing AndroidStarters](https://medium.com/androidstarters/introducing-androidstarters-4a59514c82e1)

### 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.

* * *