Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7842707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:23:03+00:00 2026-06-02T16:23:03+00:00

I’m having trouble building a layout. My situation is this: I have an Activity

  • 0

I’m having trouble building a layout. My situation is this:

I have an Activity that runs and has a layout defined for both normal and landscape, but they are built in runtime from onCreate().

In onCreate() I make the call to setContentView(my_normal_layout) which is then added to using a lot of addView()‘s etc and works fine. However I am also trying to build my landscape layout but have the problem that when I try and use findViewById() to get my base layout which is part of my layout file stored in res/layout-land it returns null.

Now I’ve looked at solutions for people having the null return problem but people are suggesting that setContentView must be executed first. However I don’t want to set the content view to be my landscape layout, I only want that to happen when the screen is rotated (it does this automatically?).

So does anyone know how I can get around this problem of using findViewById and altering my view that isn’t set as the content view?

I can post any lines of code that are required but I’m hoping that explanation is good enough.
Thanks,

Josh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:23:03+00:00Added an answer on June 2, 2026 at 4:23 pm

    If I understand correctly, you have different UI elements in the two different layout files.

    If that is the case then you can still name the layout files the same (one in /res/layout and one in /res/layout-land) and use setContentView(...) to automatically inflate the correct one.

    After that, all you need to know is what the current orientation is (portrait or landscape) in order to know which bits of code to call with findViewById(...).

    You can find the orientation using…

    getWindowManager().getDefaultDisplay().getOrientation();
    

    If you are using API 8 (Android v2.2) or later, the above is deprecated however and you should call getRotation() instead of getOrientation().

    See Display.getOrientation()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.