Android RecyclerView Duplicate Item when scrolling

I have a problem in RecyclerView . When I move the element to RV and then scroll, I saw that some objects are duplicated.

+6
source share
3 answers

RecyclerView will recycle the view. When you delete data, call the notifyItemChanged(pos) or notifyDataSetChanged() method.

0
source

I know him late, but I hope this helps someone. Override these two methods in your adapter.

 @Override public long getItemId(int position) { return position; } @Override public int getItemViewType(int position) { return position; } 
+12
source

This is your notifyDataSetChanged() problem.

Make sure you use it correctly.

I.e:

 private void parseJsonFeed(JSONArray response) { for (int i = 0; i < response.length(); i++) try { JSONObject obj = response.getJSONObject(i); MyData myData = new MyData(); myData.setContent_title(obj.getString("content_title")); ... ... ... ... // adding content to array homeList.add(myData); } catch (JSONException e) { e.printStackTrace(); } //Notifying the adapter that data has been added or changed //this must always be called else the recycler would not understand when to stop or start working. recyclerViewAdapter.notifyDataSetChanged(); } 
0
source

All Articles