skip to Main Content

I am trying to make a textView invisible when pressing a button. But, if the textView is already invisible I want it to become visible.

Currently I am trying sonething like this:

public void ShowAndHide(View view){
    if(textView == View.VISIBLE){
        textView.setVisibility(View.INVISIBLE);
    }
    else   {
        textView.setVisibility(View.VISIBLE);
    }
}

Where "textView" is a TextView which I have defined by id:

TextView textView;

textView = (TextView) findViewById(R.id.showMe_txt);

Anyone who knows why this does not work? Coming from a C# background and this is my first dabble with Java so quite unfamiliar.

2

Answers


  1. Chosen as BEST ANSWER

    I cannot seem to upvote your comment just yet (this is literally my first post), however this did solve my problem. Thank you!


  2. The condition should be if(textView.getVisibility() == View.VISIBLE){

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search