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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:38:03+00:00 2026-05-29T10:38:03+00:00

I am trying to make my app more tablet-friendly, and so I’m trying to

  • 0

I am trying to make my app more tablet-friendly, and so I’m trying to learn fragments. I want the typical two-pane layout, where the left side is the “navigation”, and you click on one of the elements, and it changes the fragment on the right.

I can duplicate the tutorials that use a ListFragment for the left, and if you click on one of them, it updates the “details” fragment on the right.

I’ve tried the best I can to duplicate that code, and just use a LinearLayout, with buttons for the left side, so that if a button is clicked, it loads the appropriate fragment on the right, but it’s not working.
When I commit the FragmentTransaction, I get java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. What is the child’s parent, and why do I have to call removeView on it?

I’m trying to load the fragment into a FrameLayout, but I’ve also just tried replacing another Fragment in the layout, and still get the error.

Ideally I want the left fragment to take up the whole screen until a button is pressed that requires a fragment to come in from the left, but one problem at a time I suppose.

Code

Main Activity

public class FragmentExample2Activity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

SelectorFragment (Left side)

public class SelectorFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View fragment = inflater.inflate(R.layout.selector, container);

        Button button1 = (Button) fragment.findViewById(R.id.button1);

        button1.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {

                getFragmentManager().beginTransaction().replace(R.id.detail_holder, new DetailsFragment(), "stuff").commit();

            }

        });


        return fragment;
    }
}

DetailsFragment

public class DetailsFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        return inflater.inflate(R.layout.details, container);
    }
}

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <fragment class="com.coreno.testfragment.SelectorFragment"
        android:id="@+id/select"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:layout_weight="1"
        />

    <fragment class="com.coreno.testfragment.DetailsFragment"
        android:id="@+id/detail_holder"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:layout_weight="2"
        />
    <!-- 
    <FrameLayout
        android:id="@+id/detail_holder" 
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="2"
        />
 -->
</LinearLayout>
  • 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-29T10:38:04+00:00Added an answer on May 29, 2026 at 10:38 am

    When you inflate a layout xml file, don’t specify the parent view. It sounds very counter-intuitive to not specify where you’re putting this inflated view but it works.

    So, for example, in your SelectorFragment change the line:

    View fragment = inflater.inflate(R.layout.selector, container);
    

    to

    View fragment = inflater.inflate(R.layout.selector, null);
    

    or even better

    View fragment = inflater.inflate(R.layout.selector, container, false);
    

    Don’t forget to do the same in your DetailsFragment too.

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

Sidebar

Related Questions

I am trying to make the web app more native, so I want to
I am trying to make a Facebook Connect web app more mobile friendly. I
I have an app that I am trying to make more tablet compatible. In
I am trying to make my iPhone app more robust, by ensuring that it
I'm trying to make an app I'm designing more generic and implement the command
I am trying to make an app that will pass data between two servers
I'm trying to make my app feel more customized with a shaded navigation bar.
I've got a pretty simple app I'm trying to make. What I want to
I am trying to make my app rotation friendly, but I am having some
I'm trying to make a Android Honeycomb tablet app for a social website. I

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.