Reputation: 856
I'm using Android studio and i'm trying to find a way to use a very common thing i used to do in eclipse. when i'm writing (for example) a for loop, i'm writing the word "for" then i click on Ctrl+Space and eclipse autocomplete to a for loop with all the parameters including
for (int i=0 ; i<mCheckBoxArray.length;i++){
mCheckBoxArray[i].setChecked(false);
}
but now, in Android studio it just auto complete to for(). the for loop its just an example, does anybody knows how to do this in android studio?
Upvotes: 23
Views: 18975
Reputation: 6022
Just use alt + ctrl + t
or type "try", then press alt + ctrl + t , then select "try / catch".
Upvotes: 1
Reputation: 13
I found some solution.
In Android Studio, open Live Templates page. If you dont know(I didnt find it) where it is, try this.
In java code, write "fori" then press Alt+Enter, then select "Edit Live Templates Settings". You can see it in iteration section how it is done.
You can write your own templates for "Any Loop". For examples I wrote "if statement".
On iteration section or other section(whatever you want), top-right, press + icon, select Live Template, fill "Abbreviation" and description. In template text, you can search above how to make fori or ifn.
My abbreviation text is "ifi" and template text is :
if($VAR$ == true) {
$cursor$
}
OR
My abbreviation text is "ife" and template text is :
if($VAR$ == true) {
$cursor$
}
else {
}
Press Apply and OK, then in java code write ifi or ife, see what is happening :)
You do this for "try-catch, While, Switch, Foreach, Do-While or etc.".
Upvotes: 1
Reputation: 1068
More you can see like
iter Iterate (for each..in)
itin Iterate (for..in)
itli Iterate over a List
itar Iterate elements of array
ritar Iterate elements of array in reverse order
Upvotes: 21