android - IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling -


i trying remove item recyclerview, error.

java.lang.illegalstateexception: cannot call method while recyclerview computing layout or scrolling

i using notifydatasetchanged(). how can solve this?

here adapter code

public class listadapters extends recyclerview.adapter<listadapters.myviewholder> {      public arraylist<string> tvdatalist;     context c;     int pos;     listadapters.myviewholder myviewholder;     private layoutinflater layoutinflater;     int[] arr;      public class myviewholder extends recyclerview.viewholder implements view.onclicklistener {           public edittext edttxt;         public checkbox cb;          public myviewholder(view view) {             super(view);              edttxt = (edittext) view.findviewbyid(r.id.edttxt);             cb = (checkbox) view.findviewbyid(r.id.cb);         }          @override         public void onclick(view v) {          }       }      public listadapters(context c, arraylist<string> tvdatalist) {         this.c = c;         this.layoutinflater = layoutinflater.from(c);         this.tvdatalist = tvdatalist;         arr = new int[tvdatalist.size()];         (int = 0; < 20; i++) {             arr[i] = 0;          }       }      @override     public listadapters.myviewholder oncreateviewholder(viewgroup parent, int viewtype) {         return new listadapters.myviewholder(this.layoutinflater.inflate(r.layout.list_ittm, parent, false));         //return new landingpageadapter.myviewholder(itemview);     }      public void onbindviewholder(final listadapters.myviewholder holder, final int position) {         myviewholder = holder;          final string showsbean = tvdatalist.get(position);         myviewholder.edttxt.settext(showsbean);         if (arr[pos] == 0) {             myviewholder.cb.setchecked(false);             myviewholder.edttxt.setkeylistener(null);         } else {             myviewholder.cb.setchecked(true);             myviewholder.edttxt.setfocusable(true);         }            myviewholder.cb.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {             @override             public void oncheckedchanged(compoundbutton compoundbutton, boolean b) {                      if (arr[position]==0){                         arr[position]=1;                     }else{                         arr[position]=0;                      }                  notifydatasetchanged();              }          });      }     @override     public int getitemcount() {         return tvdatalist.size();      }      public interface itemclicklistener {         void onclick(view view, int position, boolean islongclick);     } } 

as abbas said

this occurs when calling notify on bg thread. move notify ui thread

else can use notifyitemchanged(position);

this worked well.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -