Last active
September 16, 2015 13:10
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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