I am not clear how to use @Intdef when making it a flag like this:
@IntDef(
flag = true
value = {NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
this example is straight from the docs. What does this actually mean ? does it mean all of them are initially set to true ? if i do a "or" on the following:
NAVIGATION_MODE_STANDARD | NAVIGATION_MODE_LIST
what does it mean ...im a little confused whats happening here.
@Retention(value = AnnotationRetention.SOURCE) @Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS]) public annotation IntDef. Denotes that the annotated element of integer type, represents a logical type and that its value should be one of the explicitly named constants.
int. is an abbreviation for internal or for , international. Collins COBUILD Advanced Learner's Dictionary.
Using the IntDef#flag() attribute set to true, multiple constants can be combined.
Users can combine the allowed constants with a flag (such as |, &, ^ ).
For example:
public static final int DISPLAY_OP_1 = 1;
public static final int DISPLAY_OP_2 = 1<<1;
public static final int DISPLAY_OP_3 = 1<<2;
@IntDef (
flag=true,
value={
DISPLAY_OP_1,
DISPLAY_OP_2,
DISPLAY_OP_3
}
)
@Retention(RetentionPolicy.SOURCE)
public @interface DisplayOptions{}
public void setIntDefFlag(@DisplayOptions int ops) {
...
}
and Use setIntDefFalg()
with '|'
setIntDefFlag(DisplayOptions.DISPLAY_OP1|DisplayOptions.DISPLAY_OP2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With