Android RecyclerView滚动时重复项目

问题描述:

我在RecyclerView中遇到问题。当我在RV中移动物品然后滚动时,看到一些物品已经重复。Android RecyclerView滚动时重复项目

+1

添加代码,请 –

+1

看到这里http://*.com/a/36327143/3145960 –

+0

@mehrdadkhosravi答案补充现在的代码。 – RayaCoder

RecyclerView将回收视图。删除数据时,请拨打notifyItemChanged(pos)notifyDataSetChanged()方法。

+0

Sepasgozaram,(谢谢你,为我工作) – RayaCoder

这是你的notifyDataSetChanged()这是问题。

检查您是否正确使用它。

即:

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(); 
    } 

我知道它的晚,但希望这将帮助别人。在您的适配器中覆盖这两种方法。

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

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