I am getting used to using the live templates that Android Studio has.
ctrl+j
: the available ones are shown.
I try to create a Live Template that starts, writing btnClick
, the purpose is to complete the assignment code of a click event to a button.
Live template code in xml:
<templateSet group="Android">
<template name="btnClick" value="Button $var0$ = (Button) findViewById(R.id.$var1$); if ($var0$ != null) { $var0$.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //TODO click Event $END$ } }); }" description="Generate Click Button Event" toReformat="false" toShortenFQNames="true">
<variable name="var0" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="var1" expression="complete()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="true" />
<option name="JAVA_EXPRESSION" value="false" />
<option name="JAVA_DECLARATION" value="false" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="COMPLETION" value="false" />
</context>
</template>
</templateSet>
command: btnClick
code:
Button $var0$ = (Button) findViewById(R.id.$var1$);
if ($var0$ != null) {
$var0$.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO click Event
$END$
}
});
}
Variable declaration
$var0$
nothing * I try to show by default myButton1, if the user does not change anything
$var1%
= > Complete action, so that a list of the ids of the layout is displayed.
Applicable in : Java: Statement
Not if it is possible to define a default value in $ var0 $ with the text myBtn1
in case it is not modified.