3

I'm new to this how to handle app when you turn your gadget and I have a problem.

  • I'm inflating table rows into a table.
  • They are gone (View.GONE) when onCreate().
  • They appear on a click of a button.
  • but disappear when screen orientation changes.

Is there a way to preserve Visibility of a View when orientation changes?

I've not yet worked with onSaveInstanceState() or similar, just onCreate() for now.

Any suggestions would appreciated.

I'm eager to learn new stuff Thanks in advance!

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
PacQ
  • 334
  • 1
  • 7
  • 16

1 Answers1

2

Well this happens because when you rotate the device the Activity is restarted and your onCreate is called again making the TableRow hidden again, if you have the same layout for both screens then there is no need to do so just add below line in your manifest in Activity node

android:configChanges="keyboardHidden|orientation"
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
  • Thank you ingsaurabh. Worked like a charm! I've come across this but didn't know what keyboard has to do with this. Thanks a million! – PacQ Nov 22 '11 at 11:37
  • KeyBoard has to doing nothing with this but if your activity contains an EditText as first container then it will show Keyboard if this is not mentioned – ingsaurabh Nov 22 '11 at 11:47
  • Sorry I tought I have tried this orientation flag only but I guess I did something else wrong. I thank you for the explanation it will come very handy. Best regards. – PacQ Nov 22 '11 at 11:56
  • Where exactly should I put this line? It didn't work for me in the activity declaration line. – Daniel Möller Jul 16 '17 at 16:08
  • 1
    you should add `screenSize` too. `"keyboardHidden|orientation|screenSize"` – Ahmad Reza Enshaee May 06 '18 at 14:47