Skip to content

Instantly share code, notes, and snippets.

@curioustechizen
Last active September 16, 2015 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curioustechizen/5b8d4b820cbbd87b0b0e to your computer and use it in GitHub Desktop.
Save curioustechizen/5b8d4b820cbbd87b0b0e to your computer and use it in GitHub Desktop.
Android Visibility save/restore: Quick gist to demonstrate the fact that the visibility of views is not preserved across screen rotation or other save/restore cycles.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
<Button
android:id="@+id/btn_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle"
android:onClick="toggle"
/>
</LinearLayout>
public class MainActivity extends Activity {
private TextView tvHello;
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.layout);
tvHello = (TextView) findViewById(R.id.tv_hello);
}
public void toggle(View v) {
tvHello.setVisibility(View.GONE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment