Search code examples
androidnavigation-drawerslidingmenusectionheader

Add a section header in ListView Menu


I want to make a menu with some section headers. But the source code in androidhive (http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/) is not supported it.

So how to add a section header (or make a menu item to be a section header) without change the whole source code ? Please help me!

Here's the screenshot, i want to make the "Lock", "Unlock" and "Learn" item to be the section header: https://i.sstatic.net/sk1zZ.png

Here's how I add item:

navDrawerItems = new ArrayList<NavDrawerItem>();


    // adding nav drawer items to array

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[8],0));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));       //, true, "22")); để thêm cái đuôi đằng sau

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[9],0));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));       //, true, "50+"));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1)));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[10], 0));

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[7], navMenuIcons.getResourceId(7, -1)));

    // Recycle the typed array
    navMenuIcons.recycle();

UPDATE:

  • I can't use Material Design due to some personal reasons

  • What i need is Section Header. I did a "2 ListView in a Drawer and add Header in each ListView" but... yeah, it failed obviously!


Solution

  • oh, i got the answer!

    Just add isEnabled() - false and change the layout at the specific positions in the adapter.

    And my menu item changed to section header!