Josiane Ferice
Josiane Ferice

Reputation: 941

R.layout-land is cannot be resolved to a variable

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:

  1. Right click the project name and select "New -> Other -> Android XML Layout File" and click next
  2. "login.xml" for filename and "LinearLayout" for Root Element and click next
  3. Click on orientation and move it to the right and select land scape -> it shows /res/layout-land for folder name. I click finish The folder land-layout appears below the folder name layout and the message below appears:
  4. I go to project and clean it
  5. I went to Build Path -> Order and Eport and make sure Android 4.2.2 is check
  6. I made sure that the there is no upper case or space in the folder name and or the xml file name again
  7. I build the project again with no luck.
  8. In the build path, I move the gen folder above the scr. I close the project exist eclipse. Reopen eclipse and rebuild the project
  9. I check and don't have Android.R.* imported

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

Answers (3)

codeMagic
codeMagic

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

Matt Wolfe
Matt Wolfe

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

wtsang02
wtsang02

Reputation: 18873

You can use use R.layout.login It will automatically use your layout-land when it is in landscape. Same as any other folders with any other suffix like -xlarge , -hdpi , they will automatically be used when it is apporpriate.

More reference is here on this page

Upvotes: 0

Related Questions