android - Removing items from recycler view generates an error -


i want remove items recyclerview. able remove single item @ time unable remove multiple items @ once. below code removing items:

final  online2_g_s online2_g_s = online2_g_slist.get(position);  if (online2_g_s.getpmrp()==0){    removeitem(holder.getadapterposition()); }  private void removeitem(final int position) {     new handler().post(new runnable() {         @override         public void run() {              try{                 log.i("sand36", string.valueof(position)+" "+online2_g_slist.get(position));                 online2_g_slist.remove(position);                 notifyitemremoved(position);                 notifyitemrangechanged(position, online2_g_slist.size());              }catch (exception e){                 log.i("sand36", string.valueof(e));             }         } }); 

and here error getting while removing items:

09-14 09:09:36.816 26394-26394/com.parse.awaazdo i/sand36: java.lang.indexoutofboundsexception: invalid index 4, size 4    09-14 09:09:36.817 26394-26394/com.parse.awaazdo i/sand36: java.lang.indexoutofboundsexception: invalid index 2, size 2 09-14 09:09:36.870 26394-26394/com.parse.awaazdo i/sand36: java.lang.indexoutofboundsexception: invalid index 1, size 1 

try code in

notifyitemrangechanged(position, online2_g_slist.size());  

use line above.

notifyitemrangechanged(position, online2_g_slist.size()); online2_g_slist.remove(position); notifyitemremoved(position);` 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -