Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function that returns visibility

Tags:

android

I was writing a function that is returning a visibility - but I correctly get:

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;
}

when using like this:

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

Unfortunately @Visibility annotation is hidden in View:

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

Now I can just copy this part ( works ) but it feels bad. Is there a more elegant solution I am missing here? Should I file this as a bug?

like image 233
ligi Avatar asked Jun 17 '15 21:06

ligi


1 Answers

It would definitely 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));
}
like image 197
Tom Avatar answered Sep 29 '22 13:09

Tom