私はメインのコンテンツとしてナビゲーションドロワーと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);
}
}
あなたのXMLを投稿してください。 – Bryan
@Bryanはxmlファイルを追加しました – Guest1997
あなたの 'AccountsFragment'クラスも投稿してください。これまでのところ1つの問題がありますが、なぜフラグメントが表示されないのかはわかりません。 – Bryan