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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:26:38+00:00 2026-06-18T08:26:38+00:00

I am creating a Fragment FragParent displaying several input-fields, one of which is a

  • 0

I am creating a Fragment FragParent displaying several input-fields, one of which is a sub-Fragment frag, with specialized audio controls.

The layouts of both fragments are loaded from XML in their onCreateView() methods.
Code I am using is below, but I have some questions about it:

A) is it OK to replace() the sub-Fragment if it is already returned by findFragmentByTag(), or is that an unnecessary step?

B) can the sub-Fragment be instantiated and replaced in the layout, before the parent Fragment completes the inflate() call?

<!-- language: lang-java  -->
// Load sub-Fragment with audio UI.
String fragStr = "fragment_audio_str";
int fragView = R.id.frag_audio_frame_layout;
FragmentManager fm = getChildFragmentManager();
FragmentTransaction fmt = fm.beginTransaction();
Fragment frag = (Fragment)  fm.findFragmentByTag(fragStr);
if (null == frag) {
    frag = new Fragment();
}
fmt.replace(fragView, frag, fragStr); 
fmt.commit();

return inflater.inflate(R.layout.fragment_parent, container, false);
} // END onCreateView() of FragParent
  • 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-18T08:26:39+00:00Added an answer on June 18, 2026 at 8:26 am

    A) is it OK to replace() the sub-Fragment if it is already returned by findFragmentByTag(), or is that an unnecessary step?

    No, it shouldn’t be necessary to replace the fragment if it is already there. However you need to replace your child fragment if it isn’t there.

    B) can the sub-Fragment be instantiated and replaced in the layout, before the parent Fragment completes the inflate() call?

    No, you need to inflate the parent Fragment layout and then add your child Fragment to it before returning the parent’s View.

    Try something like this:

            View parentFragLayout = inflater.inflate(R.layout.fragment_parent, container, false);
            FrameLayout childFragContainer = (FrameLayout) parentFragLayout.findViewById(R.id.frag_audio_frame_layout);
    
            // Load sub-Fragment with audio UI.
            String fragStr = "fragment_audio_str";
            FragmentManager fm = getChildFragmentManager();
            Fragment frag = fm.findFragmentByTag(fragStr);
    
            // Child fragment isn't there, so add it
            if (frag == null) {
                frag = new Fragment();
                FragmentTransaction fmt = fm.beginTransaction();
                fmt.replace(childFragContainer.getId(), frag, fragStr);
                fmt.commit();
            }
            return parentFragLayout;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a three tabs that contains one fragment each now I want
I have been creating Spinner controls (Combo boxes/Drop downs) in one of my apps,
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
I'm creating ListView in AsyncTask inside Fragment . In onActivityCreated method i call AsyncTask's
I am trying to show multiple fragments on the one screen by creating them
I am creating an app which has action bar and 2 tabs. like this:
I am creating a C# TBB(C# Code fragment). For that I need to write
I am creating an application for HonyComb in which I have to display videos
I would like to have a document fragment/element on the shelf to which I've

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.