Question

I am getting a compiler error in my class for the constant "VISIBLE" that I am trying to use in the following example

  if((enterIP.getVisibility()).equals(VISIBLE)){

the compiler error is, "VISIBLE cannot be resolved to a variable"

from the Android documentation

public int getVisibility()

Added in API level 1 Returns the visibility status for this view.

Related XML Attributes android:visibility Returns One of VISIBLE, INVISIBLE, or GONE.

how do I get the numerical value of VISIBLE or how can I use it in the example I showed?

Was it helpful?

Solution 2

VISIBLE alone is nothing so you are getting VISIBLE cannot be resolved to a variable.

Just use View.VISIBLE to resolve it to that type.

VISIBLE:

int android.view.View.VISIBLE = 0 [0x0]

public static final int VISIBLE 

OTHER TIPS

use

if((enterIP.getVisibility()).equals(View.VISIBLE)) {

}

instead of

if((enterIP.getVisibility()).equals(VISIBLE)){

}

because VISIBLE is constant inside View class or you can use any View like Button,TextView to access constants from View class like enterIP.VISIBLE

VISIBLE, INVISIBLE and GONE are attributes of your enterIP View, so you would use it like this:

 if((enterIP.getVisibility()).equals(enterIP.VISIBLE)){

You have to use

View.VISIBLE

Then may be you can solve the error.

I have commented the reason why you are facing the compile time error. But if you still want to do the same has you are trying to do we can do the following.

declare the variables globally

public static final int INVISIBLE=View.INVISIBLE;
public static final int VISIBLE=View.VISIBLE;
public static final int GONE=View.GONE;

and then use you code

if((enterIP.getVisibility()).equals(VISIBLE)){

Now the error seems to be gone.

Note: Done this way avoid calling "View" class each and every time.

Hope this helps you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top