title: My recyclerview data keeps getting doubled when i switch to some other fragment and return to that fragment which has the recyclerview
body: <p>I have a MainActivity where I replace the fragments in a FrameLayout using getSupportFragmentManager().beginTransaction.replace() and the PositionsFragment as given below. </p>
  
  <p>When I open PositionFragment initially, data is perfectly displayed, but when I switch to dashboard and then again switch to PositionsFragment, the cards in the recyclerview get doubled. </p>
  
  <p>They get doubled every time I switch. I tried clearing the arrayList using productList.clear(); but didn't work. </p>
  
  <p>MainActivity where I replace the fragments.</p>
  
  <pre><code>case R.id.nav_dashboard:           getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new DashboardFragment()).commit();
                  toolbar.setTitle("Dashboard");
                  break;
              case R.id.nav_positions:
                  getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new PositionsFragment()).commit();
                  toolbar.setTitle("Positions");
                  break;
  </code></pre>
  
  <p>PositionsFragment </p>
  
  <pre><code>public class PositionsFragment extends Fragment{
      public static Spinner spinner;
      RecyclerView recyclerView;
      ProgressBar progressBar;
      ArrayList&lt;Products&gt; productList=new ArrayList&lt;&gt;();
      ArrayList&lt;String&gt; positionsArray;
      FloatingActionButton fab;
  
      public PositionsFragment() {
      }
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View v=inflater.inflate(R.layout.fragment_positions, container, false);
          return v;
      }
  
      @Override
      public void onViewCreated(@NonNull View v, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(v, savedInstanceState);
          fab=v.findViewById(R.id.positionsFab);
          progressBar=v.findViewById(R.id.progressBarPositions);
          progressBar.setVisibility(View.VISIBLE);
          spinner=v.findViewById(R.id.positionsSpinner);
          recyclerView=v.findViewById(R.id.positionsRecyclerView);
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          productList.clear();
          new fetchDataPositions(new OnPositionsFetched() {
              @Override
              public void OnPositionsFetched() {
                  progressBar.setVisibility(View.INVISIBLE);
                  positionsArray=fetchDataPositions.getArrayList();
                  for (int i=0;i&lt;positionsArray.size();i++){
                      productList.add(new Products(//data));
                  }
                  final PositionsRecyclerAdapter recyclerAdapter=new PositionsRecyclerAdapter(getActivity(),productList,getActivity());
                  recyclerView.setAdapter(recyclerAdapter);
              }
          }).execute(url);
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(getActivity(),
                  R.array.positions_spinner_array, android.R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinner.setAdapter(adapter);
      }
  }
  </code></pre>