带列表片段的导航抽屉实现

时间:2013-08-11 21:04:48

标签: android navigation-drawer

我想实现一个包含多个listfragments的导航抽屉,我该怎么做?我花时间在网上搜索,但找不到与之相关的任何内容。任何帮助,将不胜感激!

1 个答案:

答案 0 :(得分:0)

实现NavigationDrawer时,使用其onDrawerItemSelected方法切换片段:

    @Override
    public void onDrawerItemSelected(final int pos) {

         // update the main content by replacing fragments
        Fragment fragment = null;

        switch (pos) {
        case 0:
            fragment = new ListFragmentOne();
            break;
        case 1:
            fragment = new ListFragmentTwo();
            break;
        case 2:
            fragment = new ListFragmentThree();
            break;
        }

        // content_frame is a FrameLayout inside the layout of your activity - this is where the fragment will be put
        getFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();

        mDrawerList.setItemChecked(pos, true);
        // do stuff like closing the drawer...
    }

我不确定NavigationDrawer是否支持ListFragments。如果没有,只需使用包含ListView的普通片段。