Java Question Wrap Enums

Discussion in 'Libraries developers questions' started by jahswani, Jul 4, 2015.

  1. jahswani

    jahswani Active Member Licensed User

    Hi Java Doctors i have a small issue.I have this enum :
    Code:
    public enum Mode {
            FirstMode, SecondMode;
        
    }
    and this method.
    Code:
    public void setMode(Mode mode) {
            mMode = mode;
        
    }
    I want to be able to imemplement.

    Code:
    MyObject.Mode =  Mode.FirstMode

    MyObject.Mode =   Mode.SecondMode
    How to do this ?
     
  2. DonManfred

    DonManfred Expert Licensed User

    you need to write a helper-method for the enum as b4a does not know enums
    Something like
    Code:
    public void setMode(Int mode) {
        
    if (mode == 0){
            mMode = FirstMode;
        
    } else if (mode == 1){
            mMode = SecondMode;
        }
    }
     
    somed3v3loper and jahswani like this.
  3. jahswani

    jahswani Active Member Licensed User

    Thank you bro worked like a charm. I just wanted to test something and i also found this solution.
    Code:
    Type ModeType (First As String, Second As String)
    Code:
    Dim Modes As ModeType
    Modes.First = 
    "First Mode"
    Modes.Second = 
    "Second Mode"
    Then I used it like this :

    Code:
    MyObject.Mode = Modes.First
    And it worked like a charm...Thanks once more...
     
    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice