In the tournament organizer program I am working on, I use a ListView to display player data from a database. When the screen is in the Portrait orientation, I only display the player's name and win/loss record. When the screen is in the landscape position, I'd like to display more "columns" of data in the listview.
I generally understand the usage of the layout-land folder, but how do I populate the data in fields that are only in one orientation and not in the other?
Is it best to set those columns to "gone" in portr开发者_Go百科ait and populate the fields in both orientations? Or is it better to detect the orientation in software and then only populate those fields if the screen is in landscape?
Is there a third option that I don't know about?
Thanks!
There is more than one way to do it, all options you've listed will work. I can suggest another one: create two layouts, get all views in the runtime and populate them unless they're null
. Something like:
TextView tw = (TextView) findViewById(R.id.label);
if (tw != null) tw.setText("Hello, World!");
Pick your poison. :) Anyway, I'd rather go with runtime checking of orientation. This way your code would be more explicit.
精彩评论