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 7516447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:08:05+00:00 2026-05-30T01:08:05+00:00

I have a RelativeLayout with several nested LinearLayouts. By default the LinearLayouts have visiblity

  • 0

I have a RelativeLayout with several nested LinearLayouts. By default the LinearLayouts have visiblity set to gone so none of them are visible when the activity first loads. I have two buttons that should show/hide LinearLayouts when pressed. Everything works great except when the device is reoriented and the visibility attributes are reset to the default “gone” in the xml. How do I retain the current visible state of a view during orientation change?

Edit: Final code for anyone else with the issue. Basically just add visible view tag to SharedPreferences in the void that changes visibility and check for it in OnCreate.

[Activity(Label = "My Activity", Theme="@style/TitleBar")]
public class CallManagement : Activity
{
    public LinearLayout parts; 
    public LinearLayout status; 

    ISharedPreferences p;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.CallManager);

        parts = (LinearLayout)FindViewById(Resource.Id.partLayout);
        status = (LinearLayout)FindViewById(Resource.Id.statLayout);

        p = PreferenceManager.GetDefaultSharedPreferences(this);
        var visible = p.GetString("VisibleLayout", null);

        if (visible != null && visible != "None")
        {
            RelativeLayout container = (RelativeLayout)FindViewById(Resource.Id.container);
            LinearLayout current = (LinearLayout)container.FindViewWithTag(visible);
            changeVisibility(current);
        }

        Button statusb = (Button)FindViewById(Resource.Id.changeStat);
        Button partsb = (Button)FindViewById(Resource.Id.addParts);

        statusb.Click += delegate
        {
            LinearLayout current = status;
            changeVisibility(current);
        };

        partsb.Click += delegate
        {
            LinearLayout current = parts;
            changeVisibility(current);
        };
    }

    void changeVisibility(View v)
    {           
        LinearLayout current = (LinearLayout)v;

        parts.Visibility = ViewStates.Gone;
        status.Visibility = ViewStates.Gone;

        var editor = p.Edit();

        if (v.Visibility == ViewStates.Gone)
        {
            v.Visibility = ViewStates.Visible;
            editor.PutString("VisibleLayout", v.Tag.ToString());
        }
        else
        {
            editor.PutString("VisibleLayout", "None");
        }

        editor.Commit();
    }

}
  • 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-30T01:08:06+00:00Added an answer on May 30, 2026 at 1:08 am

    The way to do this is to maintain the view’s state in a field, if you have a lot of settings to maintain, you probably want to make a private class. then:

    1. override the onRetainNonConfigurationInstance method and return that instance.
    2. in the onCreate method, retrieve the instance, and if it’s not null, use it to reinstate those values. something like this.activityState = (UserAccountData) getLastNonConfigurationInstance();

    Most people don’t realize that the activity is recreated whenever you change orientation. So this lets you communicate these settings to the new instance.

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

Sidebar

Related Questions

In my Android App Activity, I have a RelativeLayout with one ImageView and a
I have a RelativeLayout to which I add buttons and set their onCLickListener to
I have a RelativeLayout that holds a set of views and i would like
I have a problem where I have several TextView objects in my Activity. More
I have a RelativeLayout with different elements. I was planning to have two ListViews
In my foo_layout.xml file I have a subclassed RelativeLayout: <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android
I have a problem with two Textviews on the same height in a RelativeLayout
I have a layout defined in XML. It contains also: <RelativeLayout android:id=@+id/item android:layout_width=fill_parent android:layout_height=wrap_content
I' have a view that contains several textViews an ImageView and a Button .
I have a relative layout with several ImageViews (with transparent areas) above each other.

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.