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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:03:48+00:00 2026-05-28T14:03:48+00:00

I am trying to build an App which is swapping its fragments by interactions

  • 0

I am trying to build an App which is swapping its fragments by interactions with its user.
There is a Fragment defined in the Activity’s XML and a LinearLayout which should contain another Fragment.

My main activity:

public class DashActivity extends Activity {
private static final String TAG = "DashActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dashboard);
    //-- Instantiate Fragmentstuff
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    ActivitystreamFragment asf = new ActivitystreamFragment();

    fragmentTransaction.add(R.id.rightfrag, asf);
    fragmentTransaction.commit();
    Log.i(TAG, "RightView has been committed");
}

its XML file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <fragment
    android:id="@+id/fragment_dashboard"
        android:layout_width="5dp"
        android:layout_height="fill_parent"
        android:layout_marginLeft="20dp"
        android:layout_weight="0.97"
        android:name="de.upb.cs.ginkgo.tablet.ui.fragments.DashboardFragment" >
    <!-- Preview: layout=@layout/fragment_dashboard -->
        </fragment>
    <LinearLayout
        android:id="@+id/rightfrag"
        android:layout_width="450dp" 
        android:layout_height="match_parent"
        android:layout_weight="1" 
        android:layout_marginTop="10dp"
        android:layout_marginBottom="15dp"
        android:layout_marginRight="10dp" >
    </LinearLayout>
</LinearLayout>

My fragment:

public class ActivitystreamFragment extends ListFragment {
private static final String TAG = "ActivitystreamFragment";
ArrayList<Status> states;

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        Log.i(TAG,"Begin: Inflate");
        View root = inflater.inflate(R.layout.fragment_activitystream, container);
        Log.i(TAG,"Finished: Inflate");
        if(root == null)
            Log.e(TAG, "omg Inflate == null");
        return root;
        }

 @Override
 public void onCreate(Bundle savedInstanceState){
     super.onCreate(savedInstanceState);
     states = new ArrayList<Status>();
     // THE FOLLOWING HAS TO BE DELETED LATER!!
     Profile p1 = new Profile("1", null, "Max Muster", 
             null, null, null, null, null, null, null);
     Status status1 = new Status(p1,"Hello world", "12.02.2012", null);
     states.add(status1);
     // --- DELTE ----------------------------
     ActivitystreamAdapter asa = new ActivitystreamAdapter(getActivity(), R.layout.list_item_event, states);
     setListAdapter(asa);
     Log.i(TAG, "onCreate is done");

 }

}

Fragments XML:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"

        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:drawSelectorOnTop="false"
        android:background="@drawable/back_rightfrag" >

</ListView>

And the output from Logcat:

01-25 14:14:29.788: I/Process(781): Sending signal. PID: 781 SIG: 9
01-25 14:17:32.387: I/DashActivity(814): RightView has been committed
01-25 14:17:32.387: I/ActivitystreamFragment(814): onCreate is done
01-25 14:17:32.397: I/ActivitystreamFragment(814): Begin: Inflate
01-25 14:17:32.467: D/dalvikvm(814): GC_FOR_ALLOC freed 86K, 3% free 6509K/6663K, paused 59ms
01-25 14:17:32.477: I/dalvikvm-heap(814): Grow heap (frag case) to 6.902MB for 513744-byte allocation
01-25 14:17:32.597: D/dalvikvm(814): GC_CONCURRENT freed 3K, 3% free 7007K/7175K, paused 4ms+4ms
01-25 14:17:32.657: I/ActivitystreamFragment(814): Finished: Inflate
01-25 14:17:32.657: D/AndroidRuntime(814): Shutting down VM
01-25 14:17:32.657: W/dalvikvm(814): threadid=1: thread exiting with uncaught exception (group=0x40014760)
01-25 14:17:32.677: E/AndroidRuntime(814): FATAL EXCEPTION: main
01-25 14:17:32.677: E/AndroidRuntime(814): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.upb.cs.ginkgo.tablet/de.upb.cs.ginkgo.tablet.ui.DashActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.ActivityThread.access$500(ActivityThread.java:122)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.os.Looper.loop(Looper.java:132)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.ActivityThread.main(ActivityThread.java:4123)
01-25 14:17:32.677: E/AndroidRuntime(814):  at java.lang.reflect.Method.invokeNative(Native Method)
01-25 14:17:32.677: E/AndroidRuntime(814):  at java.lang.reflect.Method.invoke(Method.java:491)
01-25 14:17:32.677: E/AndroidRuntime(814):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-25 14:17:32.677: E/AndroidRuntime(814):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-25 14:17:32.677: E/AndroidRuntime(814):  at dalvik.system.NativeStart.main(Native Method)
01-25 14:17:32.677: E/AndroidRuntime(814): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.view.ViewGroup.addViewInner(ViewGroup.java:3011)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.view.ViewGroup.addView(ViewGroup.java:2900)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.view.ViewGroup.addView(ViewGroup.java:2857)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.view.ViewGroup.addView(ViewGroup.java:2837)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:787)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:977)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.BackStackRecord.run(BackStackRecord.java:638)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1309)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.Activity.performStart(Activity.java:4406)
01-25 14:17:32.677: E/AndroidRuntime(814):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1788)
01-25 14:17:32.677: E/AndroidRuntime(814):  ... 11 more
  • 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-28T14:03:49+00:00Added an answer on May 28, 2026 at 2:03 pm

    Change the line

    View root = inflater.inflate(R.layout.fragment_activitystream, container);
    

    to

    View root = inflater.inflate(R.layout.fragment_activitystream, null);
    

    or even better:

    View root = inflater.inflate(R.layout.fragment_activitystream, container, false);
    

    And it should work. Don’t ask me why attaching the fragment to the container you want it to go in doesn’t work, but it doesn’t…

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

Sidebar

Related Questions

Hey i'm trying to build an app in which the user can input some
I am trying to build a jogging app which will plot the user's jogging
I am trying to build an app with a map in which the user
I'm trying to build an URL-alias app which allows the user create aliases for
I am trying to build an app which will have a bunch of cards
I'm trying to build a small app which allows downloading of multiple files at
I'm trying to build an app, which should have Flash Player control, which plays
All, I am trying to build a completely UTF-8 web app which allows users
I am trying to build an app which shows deals and offers based on
I'm trying to build an objective C app which posts data to a remote

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.