Materialdrawer: How to get the Name of DrawerItem

Created on 19 Feb 2018  路  5Comments  路  Source: mikepenz/MaterialDrawer

Going crazy getting the name of an item shown in the drawer.
My approach from existing 2015 and 2016 issues:
IDrawerItem item = drawer.getDrawerItem(drawer.getCurrentSelection());
item.getName() ----- NOT FOUND ANYMORE.

Found out if I use PrimaryDrawerItem .getName() works.
But I have different types of Items in Drawer.

question

Most helpful comment

@afarber thanks for answering ;)

All 5 comments

You could add the name as a tag...

@soenkegissel well the IDrawerItem is an interface.

if(item instanceof PrimaryDrawerItem) {
    ((PrimaryDrawerItem) item).getName();
}

@afarber thanks for answering ;)

Allright - I gave the drawerItem a tag.

IDrawerItem item = drawer.getDrawerItem(drawer.getCurrentSelection());
if(item != null)
Log.d(TAG, "Toolbar subTitle: "+ item.getTag());

This returns "Toolbar subTitle: 2131562033"

Did it like this:
getResources().getString((Integer) item.getTag()) because tag is object filled with R.string in my case.
Thank you very much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wayne1203 picture wayne1203  路  3Comments

sonh picture sonh  路  3Comments

jd-alexander picture jd-alexander  路  4Comments

HanderWei picture HanderWei  路  3Comments

y2kshane picture y2kshane  路  4Comments