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 :
    public enum Mode {
            FirstMode, SecondMode;
    and this method.
    public void setMode(Mode mode) {
            mMode = mode;
    I want to be able to imemplement.

    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
    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.
    Type ModeType (First As String, Second As String)
    Dim Modes As ModeType
    Modes.First = 
    "First Mode"
    Modes.Second = 
    "Second Mode"
    Then I used it like this :

    MyObject.Mode = Modes.First
    And it worked like a charm...Thanks once more...
    DonManfred likes this.
  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