'How to auto complete for loop in Android studio
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?
Solution 1:[1]
You can try fori
from suggestion list
Solution 2:[2]
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
Solution 3:[3]
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.".
Solution 4:[4]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bhavesh Hirpara |
Solution 2 | jettimadhuChowdary |
Solution 3 | |
Solution 4 | Anandh Krishnan |