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

  • SEARCH
  • Home
  • 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 1045241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:57:16+00:00 2026-05-16T15:57:16+00:00

I am having trouble setting up landscape mode in my application. I have a

  • 0

I am having trouble setting up landscape mode in my application.

I have a /res folder that contains a layout folder and a layout-land folder

layout
-----main.xml

layout-land
-----main.xml

My /layout-land/main.xml contains different UI elements than /layout/main.xml. How can I map each layout appropriately when the user has switched to landscape mode and vice versa?

I am basically displaying a full screen ImageView when the user switches to landscape mode. The ImageView will download an image from the internet and display it. Switching back to portrait, should simply go back to my portrait mode, which has a different set of UI components.

I get a crash when I switch to landscape mode:

because I can’t get the id:

chartImageViewLandscape = (ImageView) this.findViewById(R.id.chartImageViewLandscape);

chartImageViewLandscape is in /layout-land/main.xml

How can I get a reference to this?

  • 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-05-16T15:57:17+00:00Added an answer on May 16, 2026 at 3:57 pm

    Sheehan, regarding onRetainNonConfigurationInstance(), below is what I am currently doing for my app in progress. I have the feeling I’m overcomplicating it though, I think there’s a simpler way; however, this works just fine for me currently:

    So in my activity class “RotationMenu.java”:

    private Object catcher;
    //lots of non-related code here
    
    //directoryList is a returned list of selected directories, that I wish to
    //retain in the event of an orientation state change.
    String[] directoryList = new String[arrayList.size()];
    arrayList.toArray(directoryList);
    
    //here, I set the class Object catcher to the directoryList
    catcher = directoryList;
    
    //rest of non-related code
    
    //this method is called when the orientation changes (for me,
    //when I open my Droid's hardware keyboard)
    public Object onRetainNonConfigurationInstance()
    {
        //If I've entered anything into my catcher Object, it will be kept
        //across orientation changes.
        final Object data = catcher;
        return data;
    }
    

    Now, in my onCreate(Bundle savedInstanceState) method:

    //We retrieve the stored Object and cast it to a String array
    final Object recipient = (String[]) getLastNonConfigurationInstance();
    
    //in case the state changes again before the code that sets the directories is run
    catcher = recipient;
    
    //if there was any stored data, we can now reinstate the list adapter where the
    //directoryList was originally being used.
    if(recipient != null)
    {
        returnedDirectories.setAdapter(new ArrayAdapter<String>(
            this.getBaseContext(),
            R.layout.simple_list_item_small,
            (String[])recipient));
    }
    

    Again, this is how I am doing it currently. If anyone knows of a more efficient method, by all means comment. 🙂

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

Sidebar

Related Questions

I'm having trouble setting the path to a DLL that is not in the
I am having trouble setting up jpa mappings for some entities. I have a
I am having trouble setting up the configuration of Spring.Net so that I can
I am having trouble setting the content on a tab that I've inflated from
I have a script which successfully creates new nodes. But I'm having trouble setting
I'm having trouble when I flip my iPad app around to landscape mode. When
I'm having trouble setting up Teamcity and Git. I have a git repo checked
I am having trouble setting up a Fluent NHibernate HasMany collection. I have set
I am having trouble setting the path to jquery in an mvc app. In
We're having trouble setting window captions using cyrillic or japanese characters. We either see

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.