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

The Archive Base Latest Questions

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

I am attempting to create an Activity which contains some TextViews at the top

  • 0

I am attempting to create an Activity which contains some TextViews at the top and then two Fragments below, side to side. The left Fragment contains a LinearLayout with clickable TextViews which are used to allow the user to determine which Fragment is displayed on the right. How can I reserve the Fragment space on the right so that I can dynamically switch the Fragments out?

My current attempt looks like this:
main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<!-- TextViews go here -->

<fragment
    android:id="@+id/fragmentSelector"
    android:name="com.metastable.android.pe.FragmentSelector"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignRight="@+id/empireNameTV"
    android:layout_below="@+id/empireNameTV" />


<fragment
    android:id="@+id/fragmentScreen"
    android:name="com.metastable.android.pe.FragmentSummary"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignTop="@+id/fragmentSelector"
    android:layout_toRightOf="@+id/fragmentSelector" />

</RelativeLayout>

fragmentSelector for the moment will always be there so having it loaded at the creation of the activity is fine, the issue is with my fragmentScreen. As it stands it will load FragmentSummary which looks fine but when I attempt to replace it it’s layout remains in the background with the new Fragment laying on top of it. Here’s how I do the replace:

public void onScreenSelected(int screen) {
    Log.d("PE", "ScreenSelected called!");
    if (screen == currentScreen)
        return;

    FragmentTransaction ft =  fm.beginTransaction();
    switch (screen) {
    case SUMMARY:
        ft.replace(R.id.fragmentScreen, fragmentSummary);
        currentScreen = SUMMARY;
        break;
    case PLANET_MANAGER:
        ft.replace(R.id.fragmentScreen, fragmentPlanetManager);
        currentScreen = PLANET_MANAGER;
        break;
    }
    ft.commit();
}

My guess is that you cannot replace a fragment that was loaded from a layout so I need a way to save the space in the layout and load the Fragments programmatically. Any suggestions are appreciated.

  • 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-02T12:07:04+00:00Added an answer on June 2, 2026 at 12:07 pm

    A work around in my opinion is making the unwanted fragments invisible.
    Like below,

    <LinearLayout>
    
        <FrameLyout>
    
            //fragment 1 here
    
        </FrameLyout>
    
        <FrameLyout>
    
            //fragment 2 here
    
        </FrameLyout>
    
    </LinearLayout>
    

    Now you can hide the fragment by making it’s parent frame layout invisible or gone.

    I hope this will solve your problem..

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

Sidebar

Related Questions

Im attempting to create a new operator :? on lists, which operates the same
I'm attempting to create a BitTorrent library in C# as a side project, for
I'm attempting to create a method in Haskell which I would think is very
I am attempting to create a tab based activity with seven tabs. Tabhost won't
I'm attempting to create a ListView where I can draw some basic shapes into
I'm attempting to create a contacts application that has two main entities - person
I'm attempting to create an Activity and unfortunately every time I want to grab
I attempting to create an 800x500 div with four overlapping divs inside the container
I attempting to create custom tabs using this . But when I try to
I am attempting to create my own custom Autocomplete style dropdown control in c#

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.