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