views:

40

answers:

3

I set sameting to invisible like this on Android:

myImageView.setVisibility(View.INVISIBLE);

And then visible like this:

myImageView.setVisibility(View.VISIBLE);

I don't know if myImageView is visible or not now, how can I check it like this:

if (IF myImageView IS VISIBLE) {
Do something
} else {
Do something else
}

How can I do that? What do I have to write within the brackets?

+1  A: 

You'd use the corresponding method getVisibility(). Method names prefixed with 'get' and 'set' are Java's convention for representing properties. Some language have actual language constructs for properties but Java isn't one of them. So when you see something labeled 'setX', you can be 99% certain there's a corresponding 'getX' that will tell you the value.

colithium
A: 

Use:

if(view.getVisibility()){
    //If view is visable run code here
}else{
    //If view is not visable run code here
}

If you're using eclipse you can just type object.get or object.set and function suggestions will come up and you can look through the list to find the property you're interested in.

Fsmv
+4  A: 

Although View.getVisibility() does get the visibility, its not a simple true/false. A view can have its visibility set to one of three things.

View.VISIBLE The view is visible.

View.INVISIBLE The view is invisible, but any spacing it would normally take up will still be used. Its "invisible"

View.GONE The view is gone, you can't see it and it doesn't take up the "spot".

So to answer your question, you're looking for:

if (myImageView.getVisibility() == View.VISIBLE) {
    // Its visible
} else {
    // Either gone or invisible
}
William