Make coding faster on Android Studio with Templates — Part 2 (File and Code Templates)

Ikhwan Koto
3 min readMay 6, 2020
Banner Template part 2

Hello everyone, welcome to Part two. In this post, we will discuss File and Code Templates.

If you haven’t read the first part, you can read on this link:

If you want to read this post in Bahasa, you can open this link: https://www.yukngoding.id/2020/04/19/buat-ngoding-lebih-cepat-di-android-studio-dengan-templates-part-2-file-and-code-templates/

For the second part, we have a goal like shown below:

Good? Let’s begin

1. Click File > Settings in the menu (or Android Studio > Preferences for MacOS)

2. Click File and Code Templates

File and Code templates

3. Click button +

Add new template

4. Create Template

Form for create a template
  • Name. The name of the template we will create, and it uses when we create a file from a template
  • Extension. The extension of the template we will create. Like java (.java) or XML(.XML) and another.
  • Empty Form. It is a place for us to write the template.
  • Description. An explanation from Android Studio about the variable that has been provided and a step to create another variable depends on what the developer needed. For creating a variable in the template, we can use a format like this ${NameOfVariable}.

In this post, we will create a file template for RecyclerView’s Adapter. Fill the Empty Form with this code:

  • ${PACKAGE_NAME}, a variable that has been provided by Android Studio. It is used to write the package name in accordance with the location the file was created.
  • ${NAME}, a variable that has been provided by Android Studio. It is used to write that file name in our template
  • ${TYPE_LIST}, a variable created by us. We use it to specify the type of data for our Adapter.
  • ${LAYOUT_NAME}, a variable created by us. We use it to determine the name of our layout on Adapter.
Screenshot after filling the forms.
Screenshot after filling the forms.

5. After filling the forms, click OK

Now, you can use the template as shown at the beginning of this post.

Visit this link for another part:

Thank you :D

--

--