Android studio: how to use live template in fbc

Android Studio has support for macros that they like to call in real time - which is nice, but no one bothers anyone to explain how to use them, and least of all Android Studio. Obviously, the live fbc template was designed to make findViewById easier to use, but I can't figure out how to use it. How exactly do you use this template to create such a template, for example:

EditText e = (EditText) findViewById(R.id.m); 
+6
source share
1 answer

After long grunts, I finally realized this. On the blank line, enter "fbc", then click the tab. This gives you the following:

  (|) findViewById(R.id.); 

with a red cursor placed at "|". You enter an object type, possibly using a tab or enter autocomplete. You may need to click a tab or enter it again to go to the next field:

  (EditText) findViewById(R.id.|); 

Repeat for ID. This gives you the following:

  (EditText) findViewById(R.id.m)|; 

The entire line will be underlined because it is an expression, not an operator. Each time you have a line with an expression on it by itself, you can press Alt-Enter, then Enter again to select β€œEnter a local variable” and assign the expression to a new variable by doing this:

  EditText |viewById| = (EditText) findViewById(R.id.m); 

It automatically generates a new variable name. If everything is okay with him, just press enter to complete. If you want a different variable name, start typing a new variable name before pressing enter. Their variable name will be automatically replaced, which will give the final result:

  EditText e = (EditText) findViewById(R.id.m);| 

And how do you use the live "fbc" template! IMO, this should be part of every Android tutorial.

Editing: I later realized that the fbc template was poorly executed, and it’s much easier to fix it by going to the settings and replacing its template text as follows:

 $cast$ $var$ = ($cast$) findViewById(R.id.$resId$); 

It does it all at once. This looks a little strange until the values ​​are filled.

+9
source

All Articles