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)
}









share|improve this question




























    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)
    }









    share|improve this question


























      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)
      }









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 13:29









      Tobias Reich

      2,69322956




      2,69322956










      asked Nov 8 at 13:23









      Elsen Almasli

      61




      61
























          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)





          share|improve this answer





















          • 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


















          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);
          }





          share|improve this answer























          • 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










          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























          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)





          share|improve this answer





















          • 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















          up vote
          0
          down vote













          count = adapter.getItemCount();

          for (int i = 0 ; i < count; ++i){
          notificationItems.remove(0);
          }
          adapterForNotification.notifyItemRangeRemoved(0, count-1)





          share|improve this answer





















          • 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













          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)





          share|improve this answer












          count = adapter.getItemCount();

          for (int i = 0 ; i < count; ++i){
          notificationItems.remove(0);
          }
          adapterForNotification.notifyItemRangeRemoved(0, count-1)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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












          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);
          }





          share|improve this answer























          • 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










          • 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















          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);
          }





          share|improve this answer























          • 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










          • 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













          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);
          }





          share|improve this answer














          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);
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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 with notifyItemRangeRemoved(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










          • Try with notifyItemRangeRemoved(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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?