Make your multiple type view adapter with annotations!
Gist for Making a Multiple View Types Adapter With Annotations
Pretty easy to use.
- Create your delegate adapters, implementing DelegateAdapter, and with the annotation DelegateAdapterType. e.g:
@DelegateAdapterType(itemType = 0)
public class SimpleTextDelegateAdapter implements DelegateAdapter { ... getView() ... }
- Your main adapter have to extend the DispatcherAdapter. You will have to override getItemViewType add your delegateAdapters in the DelegateAdaptersAnnotation just like this:
@DelegateAdapters(delegateAdapters = {
SimpleTextDelegateAdapter.class,
HtmliTextDelegateAdapter.class,
GalleryDelegateAdapter.class
})
public class MyAdapter extends DispatcherAdapter{ ... }
- You're done!
You can improve this gist/lib. We can imagine for example a wrapper class containing all the delegates, and an annotation DelegateAdapterWrapper(Class) for the DispatcherAdapter, so we only pass one the wrapper as parameter. Then if you have to add a new view type for your list, the only thing you have to do is add it in the wrapper class! Pretty handy no?
This comment has been minimized.
can you make a working example of this?