How to show/hide TextView in android xml file and java file?

I think you want a toggle (As stated by the question title)

XML File:

     <Button
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:text="@string/self_destruct"
         android:onClick="hide" />

     <TextView
         android:layout_marginBottom="16dp"
         android:layout_marginRight="8dp"
         android:id="@+id/textAuthorSign"
         android:layout_gravity="right"
         android:text="- ABJ Abdul Kalam"
         android:textStyle="italic"
         android:textSize="16sp"
         android:visibility="invisible"
         android:typeface="serif"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />

Java:

 public void hide(View view) {

     TextView txtView = (TextView)findViewById(R.id.textAuthorSign);

     //Toggle
     if (txtView.getVisibility() == View.VISIBLE)
        txtView.setVisibility(View.INVISIBLE);
     else 
        txtView.setVisibility(View.VISIBLE);

     //If you want it only one time
     //txtView.setVisibility(View.VISIBLE);

 }

First get the reference to the textView:

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

Then

  textView.setVisibility(TextView.VISIBLE);

Tags:

Java

Xml

Android