Function that returns visibility

I wrote a function that returns visibility, but I understood correctly:

Must be one of: View.VISIBLE, View.INVISIBLE, View.GONE less ...

for this code:

private int getVisibilityForGlobalAndLocal(final boolean global, final boolean local) { if (global) { return View.GONE; } return local ? View.VISIBLE : View.INVISIBLE; } 

using:

  view.setVisibility(getVisibilityForGlobalAndLocal(true,false)); 

Unfortunately, the @Visibility annotation is hidden in the view:

 /** @hide */ @IntDef({VISIBLE, INVISIBLE, GONE}) @Retention(RetentionPolicy.SOURCE) public @interface Visibility {} 

Now I can just copy this part (works), but it's bad. Is there a more elegant solution that I'm missing here? Should I indicate this as an error?

+7
android
source share
1 answer

It would be nice to be able to use the @Visibility annotation, but it looks like we can't at the moment.

In the meantime, you can add the @SuppressWarnings ("ResourceType") annotation above the method in which you call setVisibility to suppress the lint error

 @SuppressWarnings("ResourceType") public void myMethod() { view.setVisibility(getVisibilityForGlobalAndLocal(true,false)); } 
+5
source share

All Articles