2016-07-18 7 views
1

フラグメントを作成し、これを別のフラグメント・レイアウトの内部で使用しました。フラグメント内のフラグメントを呼び出す方法

これは私のレイアウトのXMLです。

<WebView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/wv_facebook" 
    > 

</WebView> 


<fragment 
    class="com.loading.LoadingAnimation" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/wv_facebook_loadingAnimation" 

    /> 

私はこのfragmentのIDを取得したいと思います。私は以下の手順を使用しましたが、私はincompatible typeエラーメッセージが表示されています。あなたがgetChildFragmentManager()代わりのgetFragmentManager()を呼び出す必要があり

Loading Animation loadingAnimation; 

loadingAnimation = (LoadingAnimation) getFragmentManager().findFragmentById(R.id.wv_facebook_loadingAnimation); 

必要LoadingAnimation見つかりandroid.support.v4.app.fragment

+0

をあなたは 'loadingAnimation =(LoadingAnimation)getFragmentManager()findFragmentById(R.id.wv_facebook_loadingAnimation)、それをキャストすることができます;' – Wilik

+0

私は同じエラーメッセージに – Kirmani88

+0

何を取得しています。あなたの 'LoadingAnimation'は? 'android.app.Fragment'または' android.support.v4.app.Fragment' – Wilik

答えて

3

0

あなたもサンプルの下に試すことがあります。

DashboardFragment innerFragment = new DashboardFragment(); 

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
       innerFragment .setEnterTransition(new Slide(Gravity.RIGHT)); 
       innerFragment .setExitTransition(new Slide(Gravity.LEFT)); 
      } 


      FragmentManager fragmentManager = getFragmentManager(); 
       FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
       folderName = mFileList.get(position).getName(); 

       fragmentTransaction.add(R.id.content_frame, innerFragment, folderName); 
       fragmentTransaction.addToBackStack(folderName); 
       fragmentTransaction.commit(); 
関連する問題