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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:38:24+00:00 2026-06-13T03:38:24+00:00

I have such layout: frame_layout.xml <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/items android:layout_width=match_parent android:layout_height=match_parent> </FrameLayout>

  • 0

I have such layout:

frame_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/items"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>

Next, in FragmentActivity I do:

setContentView(R.layout.fragment_layout);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
String tag = MyListFragment.class.getName();
MyListFragment fragment = (MyListFragment)
            getSupportFragmentManager().findFragmentByTag(tag);
 if (fragment == null) {
    fragment = new MyListFragment();
    ft.add(R.id.items, fragment, tag);
 }
 else {
    ft.replace(R.id.items, fragment, tag);
 }
 ft.addToBackStack(null);
 ft.commit();

When I call this code once, fragment shown perfectly! But, when it called twice I see no content!
After some investigation, I found that problem’s caused by this:

 setContentView(R.layout.fragment_layout);

E.g., when it is called once, fragment content is perfectly shown! But I need to call setContentView a lot of times to show another fragments.

Where’s the mistake?

P.S. It’s possible to make MyListFragment hardcoded into XML, but this does not fit to me, because I need to replace layout contents with other fragments.

  • 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-13T03:38:25+00:00Added an answer on June 13, 2026 at 3:38 am

    As nobody answers, I found another solution: keep layout for every frame and show/hide them.

    That’s how I did it…. Main layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    <FrameLayout
        android:id="@+id/container1"
        android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>
    
    <FrameLayout
        android:id="@+id/container2"
     android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>
    

    That’s how I show fragment2 (belongs to container2) in fragment activity:

    findViewById(R.id.container1).setVisibility(View.GONE);
    findViewById(R.id.container2).setVisibility(View.VISIBLE);
    
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    String tag = MyFragment.class.getName();
    Fragment fragment = (Fragment)getSupportFragmentManager().findFragmentByTag(tag);
    if (fragment == null) {
       fragment = new MyFragment();
       ft.add(R.id.container2, fragment, tag);
    }
    
    ft.addToBackStack(null);
    ft.commit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools android:layout_width=wrap_content android:layout_height=wrap_content android:orientation=horizontal> <TextView
I have such a activity with my list: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
I have the following application.xml <?xml version=1.0 encoding=utf-8?> <manifest xmlns:android=http://schemas.android.com/apk/res/android package=com.currency.mobile.android> <uses-permission android:name=android.permission.INTERNET/> <application
<?xml version=1.0 encoding=UTF-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/relativeLayout1 android:layout_width=fill_parent android:layout_height=wrap_content android:background=@drawable/background > <TabHost android:id=@android:id/tabhost android:layout_width=match_parent android:layout_height=fill_parent
I have such layout on my screen Code is ... <?xml version=1.0 encoding=utf-8?> <LinearLayout
Just recently, my Android XML files which define my layout and etc have stopped
I'm learning Tkinter using online tutorials (like http://zetcode.com/gui/tkinter/layout/ ) and others. I have python
so I have my main layout as such: <div class=menu> <?php include('/menu.php'); ?> </div>
i have four imageviews in a linear layout in such a manner that only
I have such XML structure which was returned by SharePoint web services. <rs:data ItemCount=4

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.