Reputation: 941
I have a login.xml file under layout folder; I created a layout-land folder that appears right below layout with a login.xml file in it too. In my Login.java file, I can access R.layout.loging, but I can't access R.layout-land.login. I've been reading for almost two hours with no luck. Here is what I've done so far:
But no luck
My Error Message
[2013-05-29 21:01:46 - Students] 'Landscape Orientation' is not a best match for any device/locale combination.
[2013-05-29 21:01:46 - Students] Displaying it with ', , Locale Language ___Region __,
, sw320dp, w533dp, h320dp, Normal Screen, Long screen aspect ratio, Landscape Orientation,
Normal, Day time, High Density, Finger-based touchscreen, Soft keyboard, No keyboard,
Hidden navigation, No navigation, Screen resolution 800x480, API Level 17' which is
compatible, but will actually be displayed with another more specific version of the
layout.
Following is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int result = this.getResources().getConfiguration().orientation;
if(result == 1)
{
setContentView(R.layout.login);
} else
{
setContentView(R.layout-land.login //Issue here.
}
InitializeVariables();
}
I would really appreciate any kind of help/suggestion.
Upvotes: 1
Views: 1675
Reputation: 44571
You don't specify the folder. Android knows which one to use. Just use R.layout.login
and if it is in landscape then your Activity
will choose the correct Layout
According to The Docs
...Android selects which alternative resource to use at runtime, depending on the current device configuration.
Upvotes: 1
Reputation: 9294
You don't need to do this at all, android will pick the right layout file for you as long as you follow the conventions they've put in place. Just do setContentView(R.layout.login)
and the system will use the regular one from res/layout/login.xml if portrait and the one from res/layout-land/login.xml when in landscape orientation.
Upvotes: 0