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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:53:38+00:00 2026-05-25T00:53:38+00:00

In the developers’s guide, it’s said that a Fragment can be added programmatically at

  • 0

In the developers’s guide, it’s said that a Fragment can be added programmatically at run time to an existing ViewGroup. My question is : how is this ViewGroup linked to the application?

So far, I have tried to declare a ViewGroup in the xml files describing the layout of my application. But when I try to add a Fragment to it by using the public abstract FragmentTransaction add (int containerViewId, Fragment fragment, String tag) function, my application crashes (not immediatly but at the end of the onCreate function of my application).

What I actually want to do is manage several views (implemented as Fragment) in my application and to switch between them according to the user’s choices. What should I add (or change) in my approach?

Thanks in advance for the time you will spend trying to help me.

  • 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-25T00:53:39+00:00Added an answer on May 25, 2026 at 12:53 am

    ViewGroup can be simple frame layout

    <FrameLayout
    android:id="@+id/fragmentForChange"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
    

    Then for replace this frame with you fragment you need do nex:

    Bundle args = new Bundle();        
    // add needed args
    
    //create fragment and set arguments    
    Fragment fragment= MyFragment();
    fragment.setArguments(args)
    
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    // getSupportFragmentManager - uses for compatible library instead of getFragmentManager
    
    //replace frame with our fragment
    ft.replace(R.id.fragmentForChange,fragment);
    //set type of animation
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    
    //finish transaction
    ft.commit();
    

    You can hide or show fragments in transaction with command:

    ft.hide(fragment);        
    ft.show(fragment);        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason our developers can only add projects that they've created to Team
Have any other iPhone developers experienced this phenomenon? I can see his contributions in
Hi Developers/Architects, This is more of an Architectural question: I have a web application.
I often run across developers that insist on using the XHTML doctype and when
Hello fellow developers... just to make sure, I want to ask this question: How
This question is for developers who are creating ROMS/custom builds of the Android OS.
Most developers and engineers that have experience writing software and deploying with the packaged
Afternoon Developers, I have a problem that's beginning to get on my wick. I
developers! I can't understand next situation For Example I have model class Pg::City <
Developers can use Apple’s iCloud APIs to sync app data between different versions of

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.