androidfirebasefirebase-realtime-databasenavigation-drawermaterialdrawer

Refresh Collapsing itemDrawer


I am using MaterialDrawer Library in which I am setting my drawer to be collapsing items get their names and their sub items' names for Firebase database

But when I add a sub-item it doesn't appears until I collapse and expand the collapsing item again. How can I notify it when adding data?

RootRef.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            final int[] t = {0};
            Log.i("s =", String.valueOf(dataSnapshot.getKey()));
            final ExpandableDrawerItem IntentItemDrawer;

            result.addItem(IntentItemDrawer = new ExpandableDrawerItem()
                    .withName(String.valueOf(dataSnapshot.getKey()))
                    .withIcon(GoogleMaterial.Icon.gmd_collection_case_play)
                    .withIdentifier(t[0]++).withSelectable(false)
                    .withSubItems());

            RootRef.child(String.valueOf(dataSnapshot.getKey()))
                    .addChildEventListener(new ChildEventListener() {
                @Override
                public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                    IntentItemDrawer.withSubItems(new SecondaryDrawerItem()
                            .withName(String.valueOf(dataSnapshot.getKey()))
                            .withLevel(2)
                            .withIcon(GoogleMaterial.Icon.gmd_8tracks)
                            .withIdentifier(t[

Solution

  • Example from github:

    //modify an item of the drawer
    item1.withName("A new name for this drawerItem").withBadge("19").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700));
    //notify the drawer about the updated element. it will take care about everything else
    result.updateItem(item1);

    result.updateItem(/your item/);

    to expand the view try this line:

    result.getAdapter().toggleExpandable(position);