Pass as parameter the "visibility"

5

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

Ex:

private void _setVisibility(View.VISIBLE a){
    _viewLineStatus.setVisibility(a);
}
    
asked by anonymous 01.09.2014 / 20:51

1 answer

4

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

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

In your method, just have the signature accept a int , like this:

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

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

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);
}
    
01.09.2014 / 21:01