Search code examples
androidandroid-studiofindviewbyid

Android Studio fbc Live Template


fbc live template can be used as described here:

android studio: how to use the fbc live template

But this is very long and time-consuming process. Also, the change described in the answer will create default variable name e.g. textView for TextView object and we again have to rename it. So again, this takes more time than expected and unnecessary cursor movement.

How to use fbc in a more efficient way such that it requires less key strokes?


Solution

  • We can achieve this by making only a small change in fbc live template.

    Make a change in template:

    Press Ctrl + Shift + A

    Select Live Templates Settings

    enter image description here

    Select fbc under Android and click on Change and make sure that Statement and Expression are checked. Then, click OK.

    enter image description here

    Use the template:

    Declare your variable:

    TextView myVar;
    

    write your variable name which you can do pretty fast using code completion and assign fbc and then

    myVar = fbc + <TAB>
    

    this would expand to

    myVar = (TextView) findViewById(R.id.);
    

    Now, press TAB, select id and press TAB. You are done.