2016-05-29 31 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

私はその後半を知っているが、それが誰かを助けることを願っています。これら2つのメソッドをアダプタでオーバーライドします。

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

@Override 
public int getItemViewType(int position) { 
    return position; 
} 
関連する問題