Issue
I have TextView in one of my layout. I want keep it hide and only want to make it visible when button is clicked, how can I do it ? My view is like below. Thanks.
<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:typeface="serif"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Thanks
Solution
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);
}
Answered By - Shank
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.