0

I've a class MyClass that extends ListActivity. The list use 2 different xml for every row, depending to the device orientation:

layout-land/row_layout.xml
layout-port/row_layout.xml

I want that if the device is vertical the list will show the xml layout in the folder layout-port and if the device is horizontal the list will show the xml layout in the folder layout-land.

But this doesn't happen. My activity will always show layout-port/row_layout.xml, also after that I rotate the device from vertical to horizontal.

Should I use a particular method triggered on rotating device?

LotusUNSW
  • 2,027
  • 18
  • 20
Geltrude
  • 1,093
  • 3
  • 17
  • 35
  • `layout-port` should simply be called `layout` afaik. – Gusdor Nov 13 '13 at 11:24
  • In fact - there are some useful tips in this stack http://stackoverflow.com/questions/4920810/how-to-change-screen-layout-according-to-the-orientation – Gusdor Nov 13 '13 at 11:25

1 Answers1

1

I can think to one thing at this moment. Are you using android:configChanges="screenSize|orientation" in the manifest for that activity to avoid recreation of the list/adapter ?

Alex
  • 3,382
  • 2
  • 32
  • 41
  • Yes, I use: android:configChanges="orientation|keyboardHidden|screenSize" – Geltrude Nov 13 '13 at 12:27
  • If you remove it, then your activity will be recreated with the proper port/land layout, but you have to manage to save the displayed data and reload it when the config change is done. – Alex Nov 13 '13 at 12:35
  • Oh my God. All this work? :( Do you have an example or a link to? – Geltrude Nov 13 '13 at 12:37
  • Is there the possibilty, in xml, to tell: "if portrait then width=50sp else if landscape then width=100sp"? Just to avoid all the management via code! – Geltrude Nov 13 '13 at 12:42
  • No, but you can tell it from code, checking the device orientation and so on, but the best and cleanest way to do properly. Maybe this link helps http://stackoverflow.com/questions/3915952/how-to-save-state-during-orientation-change-in-android-if-the-state-is-made-of-m – Alex Nov 13 '13 at 12:47