Is there a way to get the adapter position from within a Renderer
fbis251 opened this issue · 2 comments
Hi,
I'd like to be able to get the adapter position of a View from within a Renderer. Is this possible?
One use case is passing the position to between Activities to keep the user's selection synchronized when they click a View
Thanks
Hi @fbis251 you can configure the position of the view for every renderer creating your own RvRendererAdapter
and overriding the method named updateRendererExtraValues
.
You can create your own PositionableRenderer
adding the position attribute and a PositionableRVRendererAdapter
configuring this value. Based on this change all your renderers will keep a reference to the position :) This is the method you have to override:
/**
* Empty implementation created to allow the client code to extend this class without override
* getView method.
*
* This method is called before render the Renderer and can be used in RendererAdapter extension
* to add extra info to the renderer created like the position in the ListView/RecyclerView.
*
* @param content to be rendered.
* @param renderer to be used to paint the content.
* @param position of the content.
*/
protected void updateRendererExtraValues(T content, Renderer<T> renderer, int position) {
If you think could be valuable for any library user it could be great if you send a PR adding this attribute to the current Renderer
implementation.
Is this the answer to your question?