The Original Fragment won't go to back of stack, it stays visible

RistJousiaFut

New Member
I am having some issues with FragmentTransactions. I have sucessfuly called on a fragment from the onClick method but the original \[code\]mainFragment\[/code\] 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 \[code\]Survey.java\[/code\] class or my \[code\]Details.java\[/code\] class. Any help is appreciated. Update: (Added Photos below)
Before: http://imm.io/q9vt
After Clicking "Survey Button": http://imm.io/q9wfSee code for all below:Code from Main.java\[code\]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\]Code from main.xml\[code\]<?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\]Code from Details.java <-- The original fragment\[code\]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\]Code from Details.java <-- The new fragment\[code\]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); } }\[/code\]
 
Back
Top