-
Notifications
You must be signed in to change notification settings - Fork 554
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
Dynamically add and remove listeners #427
Comments
@rusxakep, yes, we can add this feature. |
Listeners can be cleared by providing 1 or more Class objects to a unique method: User cannot pass the instance because several listeners can be attached to that instance, so it will remove them all and is not good. If instead, I provide several remove methods, it will be then possible, but it is much better to specify the .class property of the interface so it can be removed from everywhere even without instance! For instance: mAdapter.removeListener(
FlexibleAdapter.OnItemLongClickListener.class,
FlexibleAdapter.OnUpdateListener.class); Also, I will fix the set of the click and long click in the ViewHolder based of the existence of the click and long click listeners respectively. |
FYI, this functionality for example need for working with one adapter instance with more than one fragment, if you need, for example, different logic onclick/onlongclick in fragment's |
If you remove in a second moment and at runtime a long click listeners, the bound views will still have the listener attached! The event will be fired anyway, but blocked inside the event callback because listener instance inside the adapter will be empty. So, do you want also to remove the event from the bound ViewHolders? PS. Currently I already have all the bound ViewHolders in memory. |
About this code:
I thinked about function like addListener:
Or you want change all logic for listeners? |
@rusxakep, if I add this new method it must support all types, not only these 2 and the current state on already bound ViewHolders must be updated too, as I mentioned. Fine. I will remove and add the listeners from the ViewHolders too. |
Anyway, I meant about removing listeners capability from adapter, not in viewholders, because viewholder onclick/onlongclick interface do not support addListener feature. I am using one recyclerview in common activity for many fragments. Every fragment add/remove own custom items from common activity's recyclerview. In this architecture, I want with replace fragment and prepare (clear) recyclerview in activity -> replace action for click-click events too. |
I understood your use case, for that you don't need to remove the listener but just to update it: the However, your idea to remove the listener only, I have to implement it as I explained because the current ViewHolders were created with that listener and the removal of it must be propagated to the visible Views as well for completeness otherwise the event is fired however. Check the code I will commit now. |
FlexibleAdapter have addListener function, it's good. What do you think about removeListener(this) function?
The text was updated successfully, but these errors were encountered: