2017-09-11 10 views
-1

こんにちは、私は私がなぜは、フラグメントをロードすることはできません

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> 

フラグメント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> 

この行は動作していない

を知らないこの行の問題を抱えています
trans.replace(R.id.containerr,new FragmentLastComments()); 

私は、この行私は何の問題が届かないが、私は、私は問題を取得しています。この行を使用していたときを削除すると、私はここに

R.id.containerr 

を問題だと思い、私は誰かがこれを解決するために私を助けることを願っています

+0

<?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> 

そして、これを使用してフラグメントの方法を変更しますか? – Raghavendra

+0

解決策を試すhttps://stackoverflow.com/questions/14810348/android-fragment-replace-doesnt-replace-content-puts-it-on-top – Raghavendra

+0

https://i.stack.imgur.com/avPHl。 png – ShWaEkI

答えて

0

この方法を試してみて、

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

私はこれがあなたを助け願っています。

+0

私はここで問題が起こっていると思うR.id.containerr – ShWaEkI

0
FragmentManager fragmentManager = getSupportFragmentManager(); 
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
    fragmentTransaction.add(R.id.frame_aaron, fragment); 
    fragmentTransaction.addToBackStack(null); 
    fragmentTransaction.commit(); 
+0

私は問題がここにあると思うR.id.containerr – ShWaEkI

+0

最初にあなたのコンテナid.Thai IDはレイアウトIDと同じであることを確認する必要があります。 –

0

このようでframeLayoutの内側にあなたの断片を入れて:uはエラーを投稿することができ

FragmentManager manager = getFragmentManager(); 
    FragmentTransaction trans = manager.beginTransaction(); 
    trans.replace(R.id.fragment_container,new FragmentLastComments()); 
    trans.commit(); 
関連する問題