Java using enum with switch statement

Posted by MisterSquonk on Stack Overflow See other posts from Stack Overflow or by MisterSquonk
Published on 2011-11-13T01:46:09Z Indexed on 2011/11/13 1:51 UTC
Read the original article Hit count: 119

Filed under:
|
|

I've looked at various Q&As on SO similar to this question but haven't found a solution.

What I have is an enum which represents different ways to view a TV Guide...

static enum guideView {
    GUIDE_VIEW_SEVEN_DAY,
    GUIDE_VIEW_NOW_SHOWING,
    GUIDE_VIEW_ALL_TIMESLOTS
}

...when the user changes the view an event handler receives an int from 0-2 and I'd like to do something like this...

// 'which' is an int from 0-2
switch (which) {
    case NDroid.guideView.GUIDE_VIEW_SEVEN_DAY:
    ...
    break;
}

I'm used to C# enums and select/case statements which would allow something like the above and I know Java does things differently but I just can't make sense of what I need to do.

Am I going to have to resort to if statements? There will likely only ever be 3 choices so I could do it but I wondered how it could be done with switch-case in Java.

© Stack Overflow or respective owner

Related posts about java

Related posts about enums