Open eygraber opened 9 years ago
I have a TwoWayView that uses a GridLayoutManager:
<org.lucasr.twowayview.widget.TwoWayView android:id="@+id/favorite_contacts_grid" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight=".90" android:layout_marginTop="30dp" android:paddingLeft="15dp" android:paddingStart="15dp" android:paddingRight="15dp" android:paddingEnd="15dp" app:twowayview_layoutManager="GridLayoutManager" app:twowayview_numColumns="4" app:twowayview_numRows="4" android:gravity="center"/>
My adapter has a method to add items:
public void addItem(Item item) { int sortPosition = item.getSortPosition(); if(sortPosition < items.size()) { items.add(sortPosition, item); notifyItemInserted(sortPosition); } else { items.add(item); notifyItemInserted(items.size() - 1); } }
I call twv.addItemDecoration(new SpacingItemDecoration(30, 30)), and some of the grid items are out of position (either raised or lowered). If I replace notifyItemInserted with notifyDataSetChanged everything works fine.
twv.addItemDecoration(new SpacingItemDecoration(30, 30))
notifyItemInserted
notifyDataSetChanged
notifyDataSetChanged also worked for me - thank you for posting that
+1
I have a TwoWayView that uses a GridLayoutManager:
My adapter has a method to add items:
I call
twv.addItemDecoration(new SpacingItemDecoration(30, 30))
, and some of the grid items are out of position (either raised or lowered). If I replacenotifyItemInserted
withnotifyDataSetChanged
everything works fine.