How to add recyclerview item remove animation
up vote
1
down vote
favorite
when i used this it remove one element with animation
{
notificationItems.remove(0);
adapterForNotification.notifyItemRemoved(0);
adapterForNotification.notifyItemRangeRemoved(0,count-1);
}
when i used this it remove all element without animation
count = adapter.getItemCount();
for(int i = 0 ; i < count; ++i){
notificationItems.remove(0);
adapterForNotification.notifyItemRemoved(0);
adapterForNotification.notifyItemRangeRemoved(0,count-1)
}
android android-recyclerview removeall
add a comment |
up vote
1
down vote
favorite
when i used this it remove one element with animation
{
notificationItems.remove(0);
adapterForNotification.notifyItemRemoved(0);
adapterForNotification.notifyItemRangeRemoved(0,count-1);
}
when i used this it remove all element without animation
count = adapter.getItemCount();
for(int i = 0 ; i < count; ++i){
notificationItems.remove(0);
adapterForNotification.notifyItemRemoved(0);
adapterForNotification.notifyItemRangeRemoved(0,count-1)
}
android android-recyclerview removeall
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
when i used this it remove one element with animation
{
notificationItems.remove(0);
adapterForNotification.notifyItemRemoved(0);
adapterForNotification.notifyItemRangeRemoved(0,count-1);
}
when i used this it remove all element without animation
count = adapter.getItemCount();
for(int i = 0 ; i < count; ++i){
notificationItems.remove(0);
adapterForNotification.notifyItemRemoved(0);
adapterForNotification.notifyItemRangeRemoved(0,count-1)
}
android android-recyclerview removeall
when i used this it remove one element with animation
{
notificationItems.remove(0);
adapterForNotification.notifyItemRemoved(0);
adapterForNotification.notifyItemRangeRemoved(0,count-1);
}
when i used this it remove all element without animation
count = adapter.getItemCount();
for(int i = 0 ; i < count; ++i){
notificationItems.remove(0);
adapterForNotification.notifyItemRemoved(0);
adapterForNotification.notifyItemRangeRemoved(0,count-1)
}
android android-recyclerview removeall
android android-recyclerview removeall
edited Nov 8 at 13:29
Tobias Reich
2,69322956
2,69322956
asked Nov 8 at 13:23
Elsen Almasli
61
61
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
count = adapter.getItemCount();
for (int i = 0 ; i < count; ++i){
notificationItems.remove(0);
}
adapterForNotification.notifyItemRangeRemoved(0, count-1)
i get this error
– Elsen Almasli
Nov 8 at 14:00
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:7 android.support.v7.widget.RecyclerView{425ba5d VFED..... .F....ID 16,0-696,1084 #7f0a012d app:id/notification_recyclerview}, adapter:Adapters.RecyclerViewAdapterForNotification@db406ca, layout:android.support.v7.widget.LinearLayoutManager@9f4a03b, context:********
– Elsen Almasli
Nov 8 at 14:00
Dude, I did not check your indexes. That is your own problem. I just showed you, that you need to call the notifyItemRangeRemoved method after the loop.
– finki
Nov 8 at 14:20
add a comment |
up vote
0
down vote
You shouldn't be using both notifyItemRemoved()
and notifyItemRangeRemoved()
. Only use one at a time.
If you want to remove one item:
notificationItems.remove(index);
adapterForNotification.notifyItemRemoved(index);
If you want to remove all items:
int origCount = notificationItems.size();
notificationItems.clear();
adapterForNotification.notifyItemRangeRemoved(0, origCount - 1);
If you want to remove a range of items:
notificationItems.subList(startIndex, endIndex).clear();
adapterForNotification.notifyItemRangeRemoved(startIndex, endIndex);
EDIT:
If you want to remove each item one by one and show the removal animation for each, try this:
for (int i = 0; i < notificationItems.size(); i++) {
notificationItems.remove(i);
adapterForNotification.notifyItemRemoved(i);
}
I read when use notifyDataSetChanged animation disapear. and I apply this also animation disapear. What can i do for this?
– Elsen Almasli
Nov 8 at 13:37
Try withnotifyItemRangeRemoved(0, notificationItems.size() - 1)
.
– TheWanderer
Nov 8 at 13:38
Aplication terminated
– Elsen Almasli
Nov 8 at 13:46
Share the stacktrace.
– TheWanderer
Nov 8 at 13:47
Actually, check my edit. I know the reason.
– TheWanderer
Nov 8 at 13:48
|
show 6 more comments
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
count = adapter.getItemCount();
for (int i = 0 ; i < count; ++i){
notificationItems.remove(0);
}
adapterForNotification.notifyItemRangeRemoved(0, count-1)
i get this error
– Elsen Almasli
Nov 8 at 14:00
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:7 android.support.v7.widget.RecyclerView{425ba5d VFED..... .F....ID 16,0-696,1084 #7f0a012d app:id/notification_recyclerview}, adapter:Adapters.RecyclerViewAdapterForNotification@db406ca, layout:android.support.v7.widget.LinearLayoutManager@9f4a03b, context:********
– Elsen Almasli
Nov 8 at 14:00
Dude, I did not check your indexes. That is your own problem. I just showed you, that you need to call the notifyItemRangeRemoved method after the loop.
– finki
Nov 8 at 14:20
add a comment |
up vote
0
down vote
count = adapter.getItemCount();
for (int i = 0 ; i < count; ++i){
notificationItems.remove(0);
}
adapterForNotification.notifyItemRangeRemoved(0, count-1)
i get this error
– Elsen Almasli
Nov 8 at 14:00
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:7 android.support.v7.widget.RecyclerView{425ba5d VFED..... .F....ID 16,0-696,1084 #7f0a012d app:id/notification_recyclerview}, adapter:Adapters.RecyclerViewAdapterForNotification@db406ca, layout:android.support.v7.widget.LinearLayoutManager@9f4a03b, context:********
– Elsen Almasli
Nov 8 at 14:00
Dude, I did not check your indexes. That is your own problem. I just showed you, that you need to call the notifyItemRangeRemoved method after the loop.
– finki
Nov 8 at 14:20
add a comment |
up vote
0
down vote
up vote
0
down vote
count = adapter.getItemCount();
for (int i = 0 ; i < count; ++i){
notificationItems.remove(0);
}
adapterForNotification.notifyItemRangeRemoved(0, count-1)
count = adapter.getItemCount();
for (int i = 0 ; i < count; ++i){
notificationItems.remove(0);
}
adapterForNotification.notifyItemRangeRemoved(0, count-1)
answered Nov 8 at 13:54
finki
1,01711120
1,01711120
i get this error
– Elsen Almasli
Nov 8 at 14:00
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:7 android.support.v7.widget.RecyclerView{425ba5d VFED..... .F....ID 16,0-696,1084 #7f0a012d app:id/notification_recyclerview}, adapter:Adapters.RecyclerViewAdapterForNotification@db406ca, layout:android.support.v7.widget.LinearLayoutManager@9f4a03b, context:********
– Elsen Almasli
Nov 8 at 14:00
Dude, I did not check your indexes. That is your own problem. I just showed you, that you need to call the notifyItemRangeRemoved method after the loop.
– finki
Nov 8 at 14:20
add a comment |
i get this error
– Elsen Almasli
Nov 8 at 14:00
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:7 android.support.v7.widget.RecyclerView{425ba5d VFED..... .F....ID 16,0-696,1084 #7f0a012d app:id/notification_recyclerview}, adapter:Adapters.RecyclerViewAdapterForNotification@db406ca, layout:android.support.v7.widget.LinearLayoutManager@9f4a03b, context:********
– Elsen Almasli
Nov 8 at 14:00
Dude, I did not check your indexes. That is your own problem. I just showed you, that you need to call the notifyItemRangeRemoved method after the loop.
– finki
Nov 8 at 14:20
i get this error
– Elsen Almasli
Nov 8 at 14:00
i get this error
– Elsen Almasli
Nov 8 at 14:00
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:7 android.support.v7.widget.RecyclerView{425ba5d VFED..... .F....ID 16,0-696,1084 #7f0a012d app:id/notification_recyclerview}, adapter:Adapters.RecyclerViewAdapterForNotification@db406ca, layout:android.support.v7.widget.LinearLayoutManager@9f4a03b, context:********
– Elsen Almasli
Nov 8 at 14:00
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:7 android.support.v7.widget.RecyclerView{425ba5d VFED..... .F....ID 16,0-696,1084 #7f0a012d app:id/notification_recyclerview}, adapter:Adapters.RecyclerViewAdapterForNotification@db406ca, layout:android.support.v7.widget.LinearLayoutManager@9f4a03b, context:********
– Elsen Almasli
Nov 8 at 14:00
Dude, I did not check your indexes. That is your own problem. I just showed you, that you need to call the notifyItemRangeRemoved method after the loop.
– finki
Nov 8 at 14:20
Dude, I did not check your indexes. That is your own problem. I just showed you, that you need to call the notifyItemRangeRemoved method after the loop.
– finki
Nov 8 at 14:20
add a comment |
up vote
0
down vote
You shouldn't be using both notifyItemRemoved()
and notifyItemRangeRemoved()
. Only use one at a time.
If you want to remove one item:
notificationItems.remove(index);
adapterForNotification.notifyItemRemoved(index);
If you want to remove all items:
int origCount = notificationItems.size();
notificationItems.clear();
adapterForNotification.notifyItemRangeRemoved(0, origCount - 1);
If you want to remove a range of items:
notificationItems.subList(startIndex, endIndex).clear();
adapterForNotification.notifyItemRangeRemoved(startIndex, endIndex);
EDIT:
If you want to remove each item one by one and show the removal animation for each, try this:
for (int i = 0; i < notificationItems.size(); i++) {
notificationItems.remove(i);
adapterForNotification.notifyItemRemoved(i);
}
I read when use notifyDataSetChanged animation disapear. and I apply this also animation disapear. What can i do for this?
– Elsen Almasli
Nov 8 at 13:37
Try withnotifyItemRangeRemoved(0, notificationItems.size() - 1)
.
– TheWanderer
Nov 8 at 13:38
Aplication terminated
– Elsen Almasli
Nov 8 at 13:46
Share the stacktrace.
– TheWanderer
Nov 8 at 13:47
Actually, check my edit. I know the reason.
– TheWanderer
Nov 8 at 13:48
|
show 6 more comments
up vote
0
down vote
You shouldn't be using both notifyItemRemoved()
and notifyItemRangeRemoved()
. Only use one at a time.
If you want to remove one item:
notificationItems.remove(index);
adapterForNotification.notifyItemRemoved(index);
If you want to remove all items:
int origCount = notificationItems.size();
notificationItems.clear();
adapterForNotification.notifyItemRangeRemoved(0, origCount - 1);
If you want to remove a range of items:
notificationItems.subList(startIndex, endIndex).clear();
adapterForNotification.notifyItemRangeRemoved(startIndex, endIndex);
EDIT:
If you want to remove each item one by one and show the removal animation for each, try this:
for (int i = 0; i < notificationItems.size(); i++) {
notificationItems.remove(i);
adapterForNotification.notifyItemRemoved(i);
}
I read when use notifyDataSetChanged animation disapear. and I apply this also animation disapear. What can i do for this?
– Elsen Almasli
Nov 8 at 13:37
Try withnotifyItemRangeRemoved(0, notificationItems.size() - 1)
.
– TheWanderer
Nov 8 at 13:38
Aplication terminated
– Elsen Almasli
Nov 8 at 13:46
Share the stacktrace.
– TheWanderer
Nov 8 at 13:47
Actually, check my edit. I know the reason.
– TheWanderer
Nov 8 at 13:48
|
show 6 more comments
up vote
0
down vote
up vote
0
down vote
You shouldn't be using both notifyItemRemoved()
and notifyItemRangeRemoved()
. Only use one at a time.
If you want to remove one item:
notificationItems.remove(index);
adapterForNotification.notifyItemRemoved(index);
If you want to remove all items:
int origCount = notificationItems.size();
notificationItems.clear();
adapterForNotification.notifyItemRangeRemoved(0, origCount - 1);
If you want to remove a range of items:
notificationItems.subList(startIndex, endIndex).clear();
adapterForNotification.notifyItemRangeRemoved(startIndex, endIndex);
EDIT:
If you want to remove each item one by one and show the removal animation for each, try this:
for (int i = 0; i < notificationItems.size(); i++) {
notificationItems.remove(i);
adapterForNotification.notifyItemRemoved(i);
}
You shouldn't be using both notifyItemRemoved()
and notifyItemRangeRemoved()
. Only use one at a time.
If you want to remove one item:
notificationItems.remove(index);
adapterForNotification.notifyItemRemoved(index);
If you want to remove all items:
int origCount = notificationItems.size();
notificationItems.clear();
adapterForNotification.notifyItemRangeRemoved(0, origCount - 1);
If you want to remove a range of items:
notificationItems.subList(startIndex, endIndex).clear();
adapterForNotification.notifyItemRangeRemoved(startIndex, endIndex);
EDIT:
If you want to remove each item one by one and show the removal animation for each, try this:
for (int i = 0; i < notificationItems.size(); i++) {
notificationItems.remove(i);
adapterForNotification.notifyItemRemoved(i);
}
edited Nov 8 at 17:44
answered Nov 8 at 13:31
TheWanderer
5,62611025
5,62611025
I read when use notifyDataSetChanged animation disapear. and I apply this also animation disapear. What can i do for this?
– Elsen Almasli
Nov 8 at 13:37
Try withnotifyItemRangeRemoved(0, notificationItems.size() - 1)
.
– TheWanderer
Nov 8 at 13:38
Aplication terminated
– Elsen Almasli
Nov 8 at 13:46
Share the stacktrace.
– TheWanderer
Nov 8 at 13:47
Actually, check my edit. I know the reason.
– TheWanderer
Nov 8 at 13:48
|
show 6 more comments
I read when use notifyDataSetChanged animation disapear. and I apply this also animation disapear. What can i do for this?
– Elsen Almasli
Nov 8 at 13:37
Try withnotifyItemRangeRemoved(0, notificationItems.size() - 1)
.
– TheWanderer
Nov 8 at 13:38
Aplication terminated
– Elsen Almasli
Nov 8 at 13:46
Share the stacktrace.
– TheWanderer
Nov 8 at 13:47
Actually, check my edit. I know the reason.
– TheWanderer
Nov 8 at 13:48
I read when use notifyDataSetChanged animation disapear. and I apply this also animation disapear. What can i do for this?
– Elsen Almasli
Nov 8 at 13:37
I read when use notifyDataSetChanged animation disapear. and I apply this also animation disapear. What can i do for this?
– Elsen Almasli
Nov 8 at 13:37
Try with
notifyItemRangeRemoved(0, notificationItems.size() - 1)
.– TheWanderer
Nov 8 at 13:38
Try with
notifyItemRangeRemoved(0, notificationItems.size() - 1)
.– TheWanderer
Nov 8 at 13:38
Aplication terminated
– Elsen Almasli
Nov 8 at 13:46
Aplication terminated
– Elsen Almasli
Nov 8 at 13:46
Share the stacktrace.
– TheWanderer
Nov 8 at 13:47
Share the stacktrace.
– TheWanderer
Nov 8 at 13:47
Actually, check my edit. I know the reason.
– TheWanderer
Nov 8 at 13:48
Actually, check my edit. I know the reason.
– TheWanderer
Nov 8 at 13:48
|
show 6 more comments
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208651%2fhow-to-add-recyclerview-item-remove-animation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown