Android: Navigation Drawer SubMenu: How to Collapsible navigation items
Asked Answered
W

1

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?

Wenzel answered 17/6, 2013 at 14:17 Comment(3)
It's an ExpandableListView, you can add child only to parent 5.Alcoholicity
@Milanix Actually I need to add children to Parent 5 & Parent 7, is that not possible?Wenzel
So what's the problem? Use ExplandableListView as said earlier.Alcoholicity
H
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

Histone answered 16/2, 2014 at 12:55 Comment(5)
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?Zusman
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)".Histone
Link is broken!Doralynne
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.Pervasive
dead link ... sorryWholism

© 2022 - 2024 — McMap. All rights reserved.