Using a ListFragment with Navigation Drawer

拜拜、爱过 提交于 2019-12-11 21:22:51

问题


I am trying to use the Navigation Drawer with my RSS Reader app. Previously I had multiple tabs with ListFragments to display the parsed feeds. I am just using Googles sample at the moment (Found here: http://developer.android.com/training/implementing-navigation/nav-drawer.html) but am running into an issue when trying to use a ListFragment.

 private void selectItem(int position) {
    // update the main content by replacing fragments
    RSSFragment fragment = new RSSFragment();
    Bundle args = new Bundle();
    args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    fragment.setArguments(args);

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mCategoryTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

In this method it tells me that I cannot use the replace method with ListFragments. So what should I be using instead to make this work?


回答1:


It looks like ListFragments cannot be used with the Navigation Drawer. However I was able to convert them to normal Fragments with a ListView and it works just fine.



来源:https://stackoverflow.com/questions/18003065/using-a-listfragment-with-navigation-drawer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!