1

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 2

1

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

0

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

1
  • 1
    This can be left as a comment as it is not an answer :) Commented Nov 1, 2022 at 17:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.