Reputation: 2731
In itemDecoration's on draw method it has a override method called getItemOffsets which I can get the adapter's position using:
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
int childCount = parent.getChildCount();
int position = parent.getChildAdapterPosition(view);
}
How ever if I try this method inside onDraw:
@Override
public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
int position = parent.getChildAdapterPosition( ??? );
}
What do I pass for the view parameters?
Upvotes: 1
Views: 698
Reputation: 12304
In onDraw()
You are working on one canvas. To modify one child, You have to iterate by all the parent's children.
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; ++i) {
View child = parent.getChildAt(i);
int childAdapterPosition = parent.getChildAdapterPosition(child);
// ...
}
Upvotes: 2