wasabeef / recyclerview-animators

An Android Animation library which easily add itemanimator to RecyclerView items.
Apache License 2.0
11.49k stars 1.98k forks source link

Item doesn't update. #40

Open jompon opened 8 years ago

jompon commented 8 years ago

Item doesn't shown when load data from internet connection.

mAdapter = new RecyclerAdapter(listItem); AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(mAdapter); ScaleInAnimationAdapter scaleAdapter = new ScaleInAnimationAdapter(alphaAdapter); mRecyclerView.setAdapter(scaleAdapter); LoadDataAsycnTask(); . .. ... listItem.addAll(objects); mAdapter.notifyDataSetChanged();

wasabeef commented 8 years ago

@jompon

notifyDataSetChanged as a standard behavior of RecyclerView dose not animation. Please use the notifyItemRemoved and notifyItemInserted.

jompon commented 8 years ago

I changed notifyDataSetChanged to notifyItemRemoved but it doesn't update UI, animate. I have activity A, B and then A -> B by activityforresult then B finish to A A receive data and call notifyItemRemoved and it doesn't happen.

christophereluc commented 8 years ago

When data is added to your data set, you're calling notifyItemRemoved(position) inside your recyclerview's adapter, yeah?

vad-zuev commented 8 years ago

issue confirmed, this is the method (inside my own adapter) that I use for item addition:

     public void add(@NonNull Entry entry) {
       data.add(entry);
       Collections.sort(data);
       int index = data.indexOf(entry);
       notifyItemInserted(index);
   }

//the index is 0 in most cases, so the new item should appear on top of the list

Used with the ScaleInAnimationAdapter the newly added item does not appear until I scroll down and then up again. Any ideas?

bveenvliet commented 8 years ago

I'm seeing this issue as well. When I comment out the AnimationAdapters the UI bound to my dataset updates the single item just fine.

ashmosaheb commented 8 years ago

I am seeing the issue to with this library. Again, updates fine with my normal adapter

wasabeef commented 8 years ago

@bveenvliet @ashmosaheb

Please use the following
notifyItemChanged(int) notifyItemInserted(int) notifyItemRemoved(int) notifyItemRangeChanged(int, int) notifyItemRangeInserted(int, int) notifyItemRangeRemoved(int, int)

If you want your animations to work, do not rely on calling notifyDataSetChanged(); as it is the RecyclerView's default behavior, animations are not triggered to start inside this method.