Materialdrawer: Can not update item name in a drawer.

Created on 7 Feb 2018  路  17Comments  路  Source: mikepenz/MaterialDrawer

Hello Mike,
Thank you for such a great library, i am having some issue when trying to update the name of an item in a drawer .this is what i am using
deviceAdd.updateName(Currentpos, new StringHolder("Name"));
It seems this code is not working .Is there any solution?

question

Most helpful comment

New release done: https://github.com/mikepenz/MaterialDrawer/releases/tag/v6.0.6

It will take ~30 minutes until maven has synced and you can use it

All 17 comments

@parmarravi which version of the library?

Currentpos is an identifier? (the name suggest otherwise)

Your items need to have an identifier, and you can use this identifier then to update. As the javadoc already shows:
https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L681

what will be the identifier ? i am storing position of an item in Currentpos.

 deviceAdd.setOnDrawerItemLongClickListener(new Drawer.OnDrawerItemLongClickListener() {
            @Override
            public boolean onItemLongClick(View view, int position, IDrawerItem drawerItem) {
                String tx = ((Nameable)drawerItem).getName().toString();
                String ipd= db.HomeLightDao().getDeviceFromName(tx).getDevip();
                Currentpos = position;
                System.out.println("LongPos:"+position);

                AddNewNavigation_items addNewNavigation_items = new AddNewNavigation_items(getApplicationContext(),ipd);
                addNewNavigation_items.show(getFragmentManager(),"edit name");
                return false;
            }
        });
}

As shown in the README you can define whatever identifier you want: https://github.com/mikepenz/MaterialDrawer#add-items-and-adding-some-functionality

If not, a identifier is automatically given to the item (after it was added to the drawer)
You can get the identifier by drawerItem.getIdentifier()

Is there any code to refresh the layout ? Item name is still not getting updated.

You used the identifier (after the item was added to the drawer) (can you check that the identifier is != 0)
and then you called the update method on the UI thread?
Which version of the drawer do you use?

Identifier is -12 .I am using latest version of drawer and updating method on ui thread.
Right now i used the previous code and passed the identifier instead of the position.
Currentpos = drawerItem.getIdentifier();

So you use 6.0.5?

Yes

Ok let me have a closer look. I'll let you know.

Ok I was able to identify a regression in the notify here: https://github.com/mikepenz/FastAdapter/blob/develop/library-core/src/main/java/com/mikepenz/fastadapter/utils/DefaultItemListImpl.java#L94

Will create an update ASAP and inform you when it's ready

Thank you mike .

Fixed in FastAdapter. will update the MaterialDrawer too soon

With the help of this Mike , (Nameable) drawerItem) .getName().getText(MainActivity.this) I am able to get log and toast message now. only thing is, it's not getting updated to UI.

don't do that :D

I released a new FastAdapter version here: https://github.com/mikepenz/FastAdapter/commit/1ecad22a1dccf6935832f187f783acec60efced0

and will update the drawer soon. Maven Central only needs a bit to sync releases

New release done: https://github.com/mikepenz/MaterialDrawer/releases/tag/v6.0.6

It will take ~30 minutes until maven has synced and you can use it

Its Working Mike thank you for the update .

Thanks so much for this fix!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pranjal-joshi picture pranjal-joshi  路  3Comments

HanderWei picture HanderWei  路  3Comments

singhalavi picture singhalavi  路  4Comments

hosseiniSeyRo picture hosseiniSeyRo  路  3Comments

wayne1203 picture wayne1203  路  3Comments