title: Android - RecyclerView item duplication on scroll
body: <p>I am testing a RecyclerView and would like to display a list of Strings. However I keep running into a strange problem. When I scroll my recycler items duplicate.
  Here is an image of my issue:
  <a href="https://i.stack.imgur.com/KMFCN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KMFCN.png" alt="enter image description here"></a>
  Here is my adapter:</p>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;LessonAdapter.TopicViewHolder&gt; {
  
  
  Context mContext;
  ArrayList&lt;String&gt; mData;
  
  LessonAdapter(Context context, ArrayList&lt;ListData&gt; list) {
      this.mContext = context;
      initData();
  }
  
  public class TopicViewHolder extends RecyclerView.ViewHolder {
  
      TextView mTopicIndexText;
      TextView mTopicNameText;
  
      public TopicViewHolder(View itemView) {
          super(itemView);
          mTopicIndexText = (TextView) itemView.findViewById(R.id.index);
          mTopicNameText = (TextView) itemView.findViewById(R.id.topic);
      }
  }
  
  private void initData(){
  
      mData = new ArrayList&lt;String&gt;();
      mData.add("Africa");
      mData.add("Antartica");
      mData.add("Asia");
      mData.add("Australia");
      mData.add("Europe");
      mData.add("North America");
      mData.add("South America");
      mData.add("Africa");
      mData.add("Antartica");
      mData.add("Asia");
      mData.add("Australia");
      mData.add("Europe");
      mData.add("North America");
      mData.add("South America");
      mData.add("Africa");
      mData.add("Antartica");
      mData.add("Asia");
      mData.add("Australia");
      mData.add("Europe");
      mData.add("North America");
      mData.add("South America");
  }
  
  
  @Override
  public TopicViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.lesson_item, parent, false);
      TopicViewHolder viewHolder = new TopicViewHolder(view);
      return viewHolder;
  }
  
  @Override
  public void onBindViewHolder(TopicViewHolder holder, int position) {
      holder.mTopicNameText.setText(mData.get(position));
  }
  
  @Override
  public int getItemCount() {
      return mData.size();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And the layout of each RecyclerItem:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="55dp"
      xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
      &lt;TextView
          android:id="@+id/index"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="1.0"
          android:layout_alignParentLeft="true"
          android:layout_centerInParent="true"
          android:layout_marginLeft="24dp"
          android:textColor="#393C3D"
          android:textSize="16sp"
          android:textStyle="bold" /&gt;
  
      &lt;TextView
          android:id="@+id/topic"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true"
          android:layout_toRightOf="@id/index"
          android:layout_marginLeft="25dp"
          android:textSize="16sp"
          android:textColor="#393C3D"
          android:maxLines="1"
          android:ellipsize="end"
          android:layout_marginRight="24dp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And how I initialize my RecyclerView:</p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_lesson, container, false);
          RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.lesson_list);
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          MyAdapter adapter = new MyAdapter(getActivity(), mData);
          recyclerView.setAdapter(adapter);
          return view;
      }
  </code></pre>
  
  <p>And the layout of the RecyclerView:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/lesson_list"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
      &lt;/android.support.v7.widget.RecyclerView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>