-1

hi I have a problem in this line I do not know why

FragmentManager manager = getFragmentManager();
        FragmentTransaction trans = manager.beginTransaction();
        trans.replace(R.id.containerr,new FragmentLastComments());
        trans.commit();

xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/containerr"
    android:layoutDirection="ltr">

</RelativeLayout>

fragment xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutDirection="ltr">


    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginTop="55dp"
        android:orientation="vertical">


        <TextView
            android:id="@+id/txt_lastcomments"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_marginBottom="10dp"
            android:text="last comments" />

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="5dp"
            android:id="@+id/rv_lastcomments"/>


    </LinearLayout>




</RelativeLayout>

this line is not working

trans.replace(R.id.containerr,new FragmentLastComments());

When I remove this line I'm not getting any problem but when I'm using this line I'm getting problem I think the problem here

R.id.containerr

I hope someone will help me to solve this

Raghavendra
  • 2,305
  • 25
  • 30
ShWaEkI
  • 1
  • 1
  • 5

3 Answers3

0

Try this way,

FragmentManager mFragmentManager=getFragmentManager();
Fragment mfragment = new FragmentLastComments();
mFragmentManager
         .beginTransaction()
         .replace(R.id.rl_main_new, fragmentDash, "tag")
         .commit();

I hope this helps you.

zephyr
  • 665
  • 6
  • 19
0
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.frame_aaron, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
Arjun Solanki
  • 236
  • 1
  • 11
0

Put your fragment inside a FrameLayout like this :

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerr"
android:layoutDirection="ltr">

                    <FrameLayout
                        android:id="@+id/fragment_container"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"/>

</RelativeLayout>

And change your Fragment method with this :

FragmentManager manager = getFragmentManager();
    FragmentTransaction trans = manager.beginTransaction();
    trans.replace(R.id.fragment_container,new FragmentLastComments());
    trans.commit();
Vodet
  • 1,491
  • 1
  • 18
  • 36