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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:11:45+00:00 2026-05-23T11:11:45+00:00

The thing is i’m creating a honeycomb app and i can’t switch between fragments

  • 0

The thing is i’m creating a honeycomb app and i can’t switch between fragments . Here’s my main code :

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    list = (ListView)findViewById(R.id.list);
    A = new FragmentA();
    B = new FragmentB();
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
    list.setAdapter(adapter);
    list.setOnItemClickListener(mylistener);
}

public void changeFragment(Fragment f){
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.fragment, f);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.addToBackStack(null);
    ft.commit();
}

   public OnItemClickListener mylistener = new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        switch(position){
        case 0 : changeFragment(A); 
            break;
        case 1 : changeFragment(B); 
            break;
        }

    }
};

I know before i put a “replace” i have to remove but how can i remove the one i’m already in ?
What is telling me in the log :
The specified child already has a parent. You must call removeView() on the child’s parent first .

  • 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-23T11:11:45+00:00Added an answer on May 23, 2026 at 11:11 am

    Have a look at the API demos FragmentLayout sample as it does something similar to what you want I believe. There’s nothing wrong with calling replace to load the first fragment as that sample demonstrates.

    Firstly add some protection so when when you click on the same list entry you don’t reload the same fragment.

    Secondly be careful when maintaining references to fragments, see link. You may want to recreate the fragments each time or use remove and add instead of replace.

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

Sidebar

Related Questions

The thing is that I've a Odata service with a default configuration: public class
The thing is that it does return one row. Here's the thing. SELECT... FROM...
Strange thing happening here. When running any unit test that calls: FileService fileService =
This thing is really bothering me. How can I get my dropdown list from
One thing I really miss when writing Common Lisp code is access to Python
This thing baffle me... I was checking my code, and decided to change the
Strange thing...theres no code this time but the using System.ServiceProcess; import gets a red
simplest thing ever but here: $j(.srch-txt).click(function() { $j(this).css(color: #155D97) }); $j is a no
Thing is, I don't see these ENUMs producing pull-down menus in CakePHP scaffolding, so
One thing I've always wanted to do is develop my very own operating system

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.