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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:15:04+00:00 2026-06-04T07:15:04+00:00

I am having some issues with FragmentTransactions. I have sucessfuly called on a fragment

  • 0

I am having some issues with FragmentTransactions. I have sucessfuly called on a fragment from the onClick method but the original mainFragment won’t “disappear” or go to back of stack. I have followed the Android Development tutorial on Fragment Transcation. I think the issue is in my Survey.java class or my Details.java class. Any help is appreciated.

Update: (Added Photos below)

Before: http://imm.io/q9vt
After Clicking “Survey Button”: http://imm.io/q9wf

See code for all below:

Code from Main.java

package mycompany.nst;

import mycompany.nst.R;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

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

    }

    Fragment _surveyFrag = new Survey();

    public void focusFragment(Fragment mainFragment) {
        FragmentManager FragMgr = getFragmentManager();
        FragmentTransaction transaction = FragMgr.beginTransaction();
        try {
            transaction.replace(R.id.mainFragment, _surveyFrag);
            transaction.addToBackStack(null);
            transaction.commit();

        } catch(Exception e){};
            transaction = null;
            FragMgr = null;     
    }

    public void survey_onClick(View view) {
        Log.i("onClick", "SURVEY BEGIN");
        focusFragment(_surveyFrag);
    }
}

Code from main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/hsdarker"
    android:baselineAligned="false"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/listFragment"
        android:name="mycompany.nst.ListFragment"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        class="mycompany.nst.ListFragment" >
        <!-- Preview: layout=@layout/list -->

    </fragment>

    <fragment
        android:id="@+id/mainFragment"
        android:name="mycompany.nst.Details"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/listFragment"
        class="mycompany.nst.Details" >
        <!-- Preview: layout=@layout/details -->

    </fragment>


</RelativeLayout>

Code from Details.java <– The original fragment

package mycompany.nst;

import mycompany.nst.R;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

    public class Details extends Fragment {
        /** Called when the activity is first created. */
        @Override
        public View onCreateView(LayoutInflater LIdetails, ViewGroup VGdetails, Bundle SaveInstancedState) {
            Log.i("DetailsFragment", "onCreateView");
            // Inflate the layout for this fragment
            return LIdetails.inflate(R.layout.details, VGdetails, false);
        }  
    }

Code from Details.java <– The new fragment

package mycompany.nst;

import mycompany.nst.R;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

    public class Survey extends Fragment {
        /** Called when the activity is first created. */ 
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            Log.i("SurveyFragment", "onCreateView");
            // Inflate the layout for this fragment
            return inflater.inflate(R.layout.survey, container, false);
        }
    }
  • 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-04T07:15:05+00:00Added an answer on June 4, 2026 at 7:15 am

    You can’t replace or remove a fragment that’s defined in XML- it becomes a non-removable part of the layout. However, if you define the fragments in code, you can replace and remove them at will.

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

Sidebar

Related Questions

I have been having some issues retrieving JSON data from a WCF service application
Having some issues accessing my param tags from within actionscript. Essentially I have the
Having some issues with the ... in ObjectiveC. I'm basically wrapping a method and
I am having some issues passing commands through to flash from javascript. My code
having some issues with a networking assignment. End goal is to have a C
Having some issues getting this MPMoviePlayerViewController to work. I have two sample URLs pointing
I am having some issues receiving UTF-8 XML files back from DHL API. As
Having some issues running my code local. I have host file setup like this:
Having some issues with C. I have this is my code: // First line
I'm having some issues returning unique results from a table that has some repeating

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.