2016-05-29 85 views
6

我在RecyclerView中遇到問題。當我在RV中移動物品然後滾動時,看到一些物品已經重複。Android RecyclerView滾動時重複項目

+1

添加代碼,請 –

+1

看到這裏http://stackoverflow.com/a/36327143/3145960 –

+0

@mehrdadkhosravi答案補充現在的代碼。 – RayaCoder

回答

0

RecyclerView將回收視圖。刪除數據時,請撥打notifyItemChanged(pos)notifyDataSetChanged()方法。

+0

Sepasgozaram,(謝謝你,爲我工作) – RayaCoder

0

這是你的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(); 
    } 
12

我知道它的晚,但希望這將幫助別人。在您的適配器中覆蓋這兩種方法。

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

@Override 
public int getItemViewType(int position) { 
    return position; 
} 
相關問題