22

Is there any auto-complete shortcut or code-generation command in Android Studio that creates a stub

switch (myEnum){

}

statement containing all of the possible case statements for a defined enum as in Eclipse?

Community
  • 1
  • 1
Francois B
  • 474
  • 5
  • 15

3 Answers3

52

Put the caret on "switch", press Alt-Enter, select "Create missing 'switch' branches".

yole
  • 92,896
  • 20
  • 260
  • 197
0

Enum.class

public enum
myEnum{
Item1,
Item2,
Item3,
Item4
}

EnumSwitchImplement.class

private Enum.myEnum mMyEnum;

switch(mMyEnum){
//put cursor here and press Alt + Enter

/*a box will come with option "create missing 'switch' branches"
select.*/
}

//your switch will convert to

switch(mMyEnum){
case Item1:
break;
case Item2:
break;
case Item3:
break;
case Item4:
break;
}

This works on Android Studio. Haven't check on Eclipse. :)

Shashank
  • 183
  • 1
  • 4
-1

Just place the mouse pointer over switch and then wait for some time. An yellow bulb will be shown as below. Click on that yellow bulb (or press ALT+Enter) and click on the option Create missing 'switch' branches option.

enter image description here

This will auto create the switch case-break statements as below. enter image description here

Hope this helps someone.

sunil
  • 6,444
  • 1
  • 32
  • 44