Java Question Wrap Enums

jahswant

Well-Known Member
Licensed User
Longtime User
Hi Java Doctors i have a small issue.I have this enum :
B4X:
 public enum Mode {
        FirstMode, SecondMode;
    }
and this method.
B4X:
  public void setMode(Mode mode) {
        mMode = mode;
    }
I want to be able to imemplement.

B4X:
MyObject.Mode =  Mode.FirstMode

MyObject.Mode =   Mode.SecondMode

How to do this ?
 

DonManfred

Expert
Licensed User
Longtime User
you need to write a helper-method for the enum as b4a does not know enums
Something like
B4X:
public void setMode(Int mode) {
    if (mode == 0){
        mMode = FirstMode;
    } else if (mode == 1){
        mMode = SecondMode;
    }
}
 

jahswant

Well-Known Member
Licensed User
Longtime User
Thank you bro worked like a charm. I just wanted to test something and i also found this solution.
B4X:
Type ModeType (First As String, Second As String)

B4X:
Dim Modes As ModeType
Modes.First = "First Mode"
Modes.Second = "Second Mode"

Then I used it like this :

B4X:
MyObject.Mode = Modes.First

And it worked like a charm...Thanks once more...
 
Top