20

I have a Navigation Drawer with 10 options Option #5 shoudl have another 7 options (like a sub menu) of some sort that is expandable/collapsible

How do I create a "Collapsible navigation items" like it is described here?

Al Fahad
  • 2,378
  • 5
  • 28
  • 37
Eric Bergman
  • 1,453
  • 11
  • 46
  • 84

1 Answers1

17

Here is a sample application which makes it:

PrashamTrivedi / DrawerLayoutTest: Link is dead

EDIT: Simple Navigational Drawer Layout in Android

@Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
    {
        if (convertView == null)
        {
            LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.drawer_group_item,parent,false);
        }

        ((TextView) convertView).setText(groupItem.get(groupPosition));
        convertView.setTag(groupItem.get(groupPosition));
        return convertView;
    }

@Override
    public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
    {
        tempChild = (ArrayList<String>) children.get(groupPosition);
        TextView text = null;

        if (convertView == null)
        {
            LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.drawer_submenu_item,parent,false);
        }

        text = (TextView) convertView;
        text.setText(tempChild.get(childPosition));

        convertView.setTag(tempChild.get(childPosition));
        return convertView;
}

And you have to create the new xml files in the layout folder (hint: create two, one for the group view and other for the submenu)

After all your side navigation must look like as below:

enter image description here

cagcak
  • 3,894
  • 2
  • 21
  • 22
  • But after I've imported your project solution into my workspace, I wasn't able to select the item under Item 4. Do you have any ideas? –  Nov 01 '14 at 06:37
  • Well, as I remember, the sample project wasn't completely backward-compatible meaning that it has min-sdk version 11. If you used the app in older devices which have before Honeycomb API, it might be the cause. If not, please consider the advice I've told: "_you have to create the new xml files in the layout folder (hint: create two, one for the group view and other for the submenu)_". – cagcak Nov 01 '14 at 19:13
  • Link is broken! – transistor Jan 05 '17 at 21:04
  • 1
    Yeah the link is broken, does anyone know where this project is now? According to the screenshot it allows the use of both ListView and ExpandableListView which is something I need help with myself. – user1676874 Feb 01 '17 at 16:04
  • dead link ... sorry – Maveňツ Sep 14 '18 at 13:52