Pass "visibility" as parameter

Asked

Viewed 98 times

5

How do I pass as parameter a visibility and then set it?

Ex:

private void _setVisibility(View.VISIBLE a){
    _viewLineStatus.setVisibility(a);
}

1 answer

4


The method parameter setVisibility class View, is int. and has the following possible values:

View.VISIBLE = 0x00000000
View.INVISIBLE = 0x00000004
View.GONE = 0x00000008

So in your method just make the signature accept a int, thus:

private void _setVisibility(int visibility) {
    _viewLineStatus.setVisibility(visibility);
}

If you want you can even do a treatment to not set an invalid value, since the class View does not make treatment:

private void _setVisibility(int visibility) {
    if(visibility != View.VISIBLE && visibility != View.INVISIBLE && visibility != View.GONE) {
        throw new RuntimeException("Deve passar um desses valores: View.VISIBLE, View.INVISIBLE ou View.GONE");
    }

    _viewLineStatus.setVisibility(visibility);
}
  • Perfect! Just what I wanted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.