android - DividerItemDecoration is not applied when RecyclerView.Adapter.notifyItemInserted() is called -
i created custom divider recyclerview extending divideritemdecoration , applying calling additemdecoration on recyclerview.
the recyclerview displays nicely untill data set changes , call notifyiteminserted. new item indeed inserted in recyclerview, displayed without custom divider (dividers other items in place).
when scroll away newly inserted item , return - appears divider in place.
edit code snippets:
mrecyclerview.additemdecoration(new gapdivideritemdecoration(mcontext, linearlayoutmanager.vertical, 16));   my custom decorator (just adds space between recyclerview items provided in dp):
public class gapdivideritemdecoration extends divideritemdecoration {  private int mspaceinpixels; private int morientation;  public gapdivideritemdecoration(context context, int orientation, float dp) {     super(context, orientation);     mspaceinpixels = dptopixels(dp);     morientation = orientation; }  private int dptopixels(float dp) {     return (int) (dp * (((float) resources.getsystem().getdisplaymetrics().densitydpi) / displaymetrics.density_default)); }  @override public void ondraw(canvas c, recyclerview parent, recyclerview.state state) {     // not draw divider }  @override public void getitemoffsets(rect outrect, view view, recyclerview parent, recyclerview.state state) {     super.getitemoffsets(outrect, view, parent, state);     if (parent.getchildadapterposition(view) != parent.getadapter().getitemcount() - 1) {         if (morientation == linearlayout.vertical) {             outrect.bottom = mspaceinpixels;         } else {             outrect.right = mspaceinpixels;         }     } }   i not provide rest of code, because pretty straight forward (besides, know working, , issue might recyclerview or custom decorator).
 
 
Comments
Post a Comment