On eclipse, when I write for
I get a macro option on autosuggestion to implement a foreach with any list that I Have. Have any way of do it on Android studio? because when I write for
on android studio I get only the traditional for and methods on autosuggestion box.
Android Studio do it in a different way :
you can use following 'live templates' to generate several types of code snippets for loop iteration :
iter Iterate using foreach loop
itli Iterate over a List using normal for loop
itar Iterate elements of array using normal for loop
ritar Iterate elements of array in reverse order using normal for loop
Enter any of the above keyword in Android Studio and press Tab key, Studio will generate template for you .
Ctrl+J
will give you all available templates in windows.
There are probably many more, just lookup 'Live Templates' in help documentation of Intellij Idea.
Android Studio has really nice live templates that come from IntelliJ. On Mac the default keybinding is command-J, but if you're not on Mac, then search your keybindings for Insert live template...
After you press the key combo to start inserting a live template, it gives you a list of templates on the screen and you can start typing to choose a template from the list. If I want to iterate over a Iterable
, I press Command-j followed by iter. It's pretty smart about reading the context and choosing likely defaults for what I want to iterate over, but it has on-screen prompts that let you enter the parameters for the template.
See https://www.jetbrains.com/idea/webhelp/live-templates.html for more info.
This is already available in Android Studio, known as Live Template.
You can have a look at the predefined in Preferences -> Live Templates.
There is also on for a foreach loop, just type:
iter
and then press ctrl + j
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With