Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The item list is not properly invalidated when an item is added after the drawer has been built #1041

Closed
waninkoko opened this issue Feb 27, 2016 · 4 comments
Assignees
Labels

Comments

@waninkoko
Copy link

Hi,

I'm having an issue (that is not happening in 4.6.4) when adding a new item, using addItem(), after the drawer has been built. The item list is not properly invalidated and the views are not updated until I start clicking on the items.

Calling drawer.getAdapter().notifyDataSetChanged() after adding the item fixes the problem but, obviously, it is not a proper fix. drawer.getItemAdapter().notifyDataSetChanged() does NOT fix the problem.

@mikepenz
Copy link
Owner

@waninkoko hi

Sorry I can't reproduce this issue. When i add an item it is added without any issues.
As the MaterialDrawer now uses the FastAdapter in the background and it properly calls notifyItemInserted on the adapter, this should not happen.

In general such issues appear when you change items inside an Adapter and notify the Adapter from a NON UI-Thread. So I assume you try to add the item from a wrong thread?

@mikepenz mikepenz self-assigned this Feb 27, 2016
@waninkoko
Copy link
Author

@mikepenz

I can confirm that the item is being added from the UI thread.

And something I forgot to say before. The drawer I'm using is just a normal drawer with a custom drawer header view.

@mikepenz
Copy link
Owner

@waninkoko what I tried to reproduce this.

  • created the Drawer within the onCreate
  • opened the Drawer to make sure I see when items are added
  • with a handler (new Handler().postDelayed()) after 2 seconds (so I am on the UI Thread) I added a new Item at the end

It properly animates and adds the item without touching the view. I tried this on my Nexus 6P and on a Emulator

@waninkoko
Copy link
Author

@mikepenz I've been trying since yesterday to fix this issue with no luck. Right now I have a very simple drawer implemented and the issue still happens.

This is my current code:

DrawerBuilder builder = new DrawerBuilder();

builder.withActivity(this);
builder.withSavedInstance(savedInstanceState);
builder.withToolbar(getToolbar());
builder.withOnDrawerItemClickListener(this);

builder.addDrawerItems(...); // here I add a simple PrimaryDrawerItem

return builder.build();

And this is the code that adds the new item (runs on the UI thread, with a delay of 5 seconds to see how it gets added):

private Handler mHandler = new Handler();

mHandler.postDelayed(new Runnable() {
    mDrawer.addItem(...); // another simple PrimaryDrawerItem
}), 5000;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants