0

I am trying to replace a fragment when a user clicks an object a list view, and I want the user to be able to tap the back button on his/her device to return to the list view.

Right now, I have in the calling method:

            ft.replace( R.id.favView, ddf);
            ft.addToBackStack(null);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();

and the XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/favView" 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.proj1.MainActivity$PlaceholderFragment">



<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true" />



</RelativeLayout>

and the XML of the subview:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:orientation="vertical" >

<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</FrameLayout>

</LinearLayout>

Here's what happens:

When I open the list view tab, and when I hit the back button, it appears like it should: List View

When I tap on an item, it appears as: List view with detail view on top

Does anyone have any suggestions? Thanks!

user2078519
  • 135
  • 2
  • 12
  • possible duplicate of [Switching fragments within tab](http://stackoverflow.com/questions/10502786/switching-fragments-within-tab) – nhaarman Oct 10 '14 at 21:52
  • I don't believe that this is a duplicate because the view appears on top of the calling view, but not when I switch tabs. Thanks! – user2078519 Oct 10 '14 at 23:11

0 Answers0