Android RecyclerView Duplicate Item When Scrolling

假装没事ソ 提交于 2019-11-30 19:22:41

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

I know its late but hope it will help someone. Override these two methods in your adapter.

@Override
public long getItemId(int position) {
    return position;
}

@Override
public int getItemViewType(int position) {
   return position;
}

It is your notifyDataSetChanged() that is the issue.

Check that you used it properly.

That is:

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();
   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!