Search code examples
visibilityandroid-dialogfragment

Hide and Show Textview with button click in Dialog fragment


I am new to programming and i hope someone can help provide me a simple code

I have a dialog fragment with a textview and a button. It loaded with both visible. when I click on the button, I need to hide the textview. when I click it again, I need the textview to be shown.

I tried textview1.setVisibility(View.GONE);

The textview still stays there, i think i am missing a refresh method???

Thanks

btnclick.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                textview1.setVisibility(View.GONE);
            }
        });

Solution

  • Hi, Use if else loop it will solve this issue for example refer this code

    boolean s=true;
    btnclick.setOnClickListener(new View.OnClickListener() {
     public void onClick(View v) {
    if(s) {
    textview1.setVisibility(View.GONE);
    s=false;
    }
    else {
    textview1.setVisibility(View.VISIBLE);
    s=true;
    }
    } });