daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. first call data -> A B C D are added to the recyclerview
  2. second call data -> A B C D E F
  3. compare data from call 1 with call 2 and add E F because they are different
  4.  
  5. the final result to be shown in the recyclerview would be the following A B C D E F
  6.      
  7. mData.remove(position);
  8. notifyItemRemoved(position);
  9. notifyItemRangeChanged(position, mData.size());
  10. notifyDataSetChanged();
  11. //this lines deletes the final button, and after add the new data
  12. JSONArray res = response_json.getJSONArray("res");
  13. for(int i=0;i<mData.size();i++){
  14.     if(i >= row_index){ //row_index I identify the index of the page to update from it
  15.         for(int j=0;j<res.length();j++){
  16.             JSONObject item = res.getJSONObject(j);
  17.             if(mData.get(i).getId() != item.getInt("id")){
  18.                 //add diferent data
  19.                 obj = new Obj();
  20.                 obj.setId_pedido(item.getInt("id"));
  21.                 obj.setValor(item.getString("valor"));
  22.                 mData.add(obj);
  23.                 notifyDataSetChanged();
  24.             }
  25.         }
  26.     }
  27. }
  28. Obj mas = new Obj();
  29. mas.setId_pedido(0);
  30. mas.setValor("OBtener mas data");
  31. mData.add(mas);
  32. //Add the final button
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top