Android @Intdef for flags how to use it

I do not understand how to use @Intdef when creating this flag:

@IntDef( flag = true value = {NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS}) 

this example is straight from docs . What does it mean? Does this mean that all of them are initially set to true? if I do "or" on the following:

 NAVIGATION_MODE_STANDARD | NAVIGATION_MODE_LIST 

what does it mean ... they are a little confused about what is happening here.

+11
android android annotations
source share
1 answer

Using the true value of the IntDef # flag () attribute allows you to combine multiple constants.

Users can combine allowed constants with a flag (for example, |, & amp ;, ^).

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); 
+14
source share

All Articles