androidandroid-studiokotlinandroid-recyclerviewepoxy

How to get Item Position in EpoxyModelWithHolder?


I'm trying to add a RecyclerView to my app using Epoxy Library I need to get position of the item in bind method in EpoxyModelWithHolder but I don't know how to do that.

I couldn't find any function to get the position of holder/item.


Solution

  • The solution is to have an Integer EpoxyAttribute in your model and in your controller set it to id from buildItemModel method.

    In your model:

    @EpoxyAttribute
    Integer position;
    

    In controller:

    public EpoxyModel<?> buildItemModel(int i, yourmodel) {
    
    return model()_.id(i).position(i);
    
    }