2016-09-23 14 views
0

私はメインのコンテンツとしてナビゲーションドロワーとSwipeRefreshLayoutを使用しています。ユーザーがナビゲーションドロワーのメニュー項目を選択したときに、SwipeRefreshLayout別の断片でAndroid-FragmentTransaction.replace()は一度しか動作しません

// Handle navigation view item clicks here. 
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
drawer.closeDrawer(GravityCompat.START); 
selectedNavItem = item.getItemId(); 

if(selectedNavItem == R.id.nav_files){ 
    filesFragment = new FilesFragment(); 
    fm = getSupportFragmentManager(); 
    FragmentTransaction transaction = fm.beginTransaction(); 
    transaction.replace(R.id.swipeLayout,filesFragment,"files"); 
    transaction.commit(); 

} else if(selectedNavItem == R.id.nav_accounts){ 
    accountsFragment = new AccountsFragment(); 
    fm = getSupportFragmentManager(); 
    FragmentTransaction transaction = fm.beginTransaction(); 
    transaction.replace(R.id.swipeLayout,accountsFragment,"accounts"); 
    transaction.commit(); 
} 
return true; 

しかし、この作品はありません:

これは私のonNavigationItemSelected()がどのように見えるかです。ナビゲーションドロワーのアイテムをクリックすると、そのフラグメントは空白のスクリーンに置き換えられます。私のonCreateメソッドもFragmentTransaction.replace()を使用しますが、うまくいくようです。

私もFragmentTransaction.remove()を試してからFragmentTransaction.add()を試しましたが、それでもうまくいかないようです。

編集:レイアウトファイル:ナビゲーション引き出しのコンテンツビューの

レイアウト:

<android.support.v4.widget.SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.harshallele.cloudpool.MainActivity" 
    tools:showIn="@layout/app_bar_main" 
    android:id="@+id/swipeLayout"> 


</android.support.v4.widget.SwipeRefreshLayout> 

これはtoolbar.Thatファイルを含むCoordinatorLayoutを含む別のレイアウトファイル内に含まれ、順番にandroid.support.v4.widget.DrawerLayout

(基本的に、これはアクティビティを追加するときにAndroidスタジオから提供されるナビゲーションドロアアクティビティ)

FilesFragmentため

レイアウト:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".fragments.FilesFragment"> 


     <android.support.v7.widget.RecyclerView 
      android:id="@+id/fileListView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical" 
     /> 


     <ProgressBar 
      android:id="@+id/itemsLoadingProgress" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:indeterminateOnly="true" 
      android:visibility="invisible" 
     /> 

</FrameLayout> 

AccountsFragmentのレイアウト(私はこれをまだ終えていないので、これは、単にデフォルトの空白の断片である):

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.harshallele.cloudpool.fragments.AccountsFragment"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="@string/hello_blank_fragment" /> 

</FrameLayout> 

編集2:

アカウント情報:

public class AccountsFragment extends Fragment { 


    public AccountsFragment() { 
     // Required empty public constructor 
    } 


    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 

     // Inflate the layout for this fragment 
     return inflater.inflate(R.layout.fragment_accounts, container, false); 
    } 

} 
+0

あなたのXMLを投稿してください。 – Bryan

+0

@Bryanはxmlファイルを追加しました – Guest1997

+0

あなたの 'AccountsFragment'クラスも投稿してください。これまでのところ1つの問題がありますが、なぜフラグメントが表示されないのかはわかりません。 – Bryan

答えて

0

ちょうどこのビットのコードでは、あまり手伝ってくれません。

  1. FilesFragmentAccountsFragmentは正しい方法で初期化されません;:問題があることもできます

  2. Layout(idがswipeLayout)はvisibility = goneです。

  3. LayoutFilesFragmentおよびAccountsFragmentは空であってもよい。

これはちょうどあなたのコードは非常に2 Fragmentsと相対XMLについてのより多くのコードを共有してください正常に動作しない理由は、無限の理由の一部です。

+0

質問が詳細に欠けていて、複数の潜在的な原因がある場合は、回答を投稿するのが時期尚早です。 OPがより多くの情報を提供するのを待ってから、実際の問題の解決法を作成してください。 – Takarii

+0

レイアウトファイルとAccountsFragmentが追加されました – Guest1997

関連する問題