title: how to prevent to creating the duplicate item while scrolling my recyclerview
body: <p>Here is My AdapterClass AvailablePateientAdapter.java
  plaese let me know the how to resolve this issue while scrolling my recyclerview each time increasing the duplicate items
  Thanks in advance.</p>
  
  <pre><code>public class AvailablePatientsAdapter extends RecyclerView.Adapter&lt;AvailablePatientsAdapter.AvailablePatientListViewHolder&gt; {
      static ReportData patData = null;
      private static String niramaiID= null;
  
      static ProgressBar progBar ;
      private static ProgressDialog progressDialog;
      private static LayoutInflater mInflater = null;
      private static ViewPendingList viewPendingList;
      private static List&lt;PatientData&gt; patients;
      private static Context mContext;
      static boolean isPending = false;
      int postion;
      private static boolean clicked = true;
      static String repStatus ;
      static Handler viewPatHandler= new Handler(){
          @Override
          public void handleMessage(Message msg){
              patData.setStatusReport(repStatus);
  //            progressDialog.show();
  
              if(niramaiID != null) {
                  if (msg.what == 1) {
                      getexaminationtable(niramaiID);
                  } else if (msg.what == 2) {
                      getsegmentationtable(niramaiID);
                  } else if (msg.what == 3) {
                      getthanalysistable(niramaiID);
                  } else if (msg.what == 4) {
                      Log.d(Config.LOG_TAG, "Response:1 status report " + patData.getStatusReport());
                      String viewPat = patData.toJson();
                      Intent addPatFromEdit = new Intent();
                      addPatFromEdit.setClass(mContext, DisplayReport.class);
                      addPatFromEdit.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                      addPatFromEdit.putExtra("display_report", viewPat);
  //                    addPatFromEdit.putExtra("is_pending",isPending);
                      if(progressDialog.isShowing()) {
                          progressDialog.hide();
                      }
                      mContext.startActivity(addPatFromEdit);
                      progBar.setVisibility(View.GONE);
                  }
              }else
              {
                  if(progressDialog.isShowing()) {
                  progressDialog.hide();
              }
                  Toast.makeText(mContext,"Niramai id is null ",Toast.LENGTH_SHORT).show();
              }
  
          }
      };
  
      static class AvailablePatientListViewHolder extends RecyclerView.ViewHolder{
          private static SimpleDateFormat oudSdf = new SimpleDateFormat("dd-MMM-yyyy");
          private static SimpleDateFormat inSdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
          AvailablePatientsAdapter mPatientBinding;
          ViewPendingList viewPendingList;
  
  
  
          AvailablePatientListViewHolder(View itemView) {
  
              super(itemView);
  
          }
  
  //       public AvailablePatientListViewHolder(ViewPendingList viewPendingList,View item){
  //           super(item);
  //           this.viewPendingList = viewPendingList;
  //        }
  
          void bind(final PatientData data) {
              RelativeLayout b = itemView.findViewById(R.id.rel_available);
              niramaiID = data.getNiramaiId();
  //            progBar.setVisibility(View.VISIBLE);
  
              itemView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
                      v.postDelayed(new Runnable(){
                          @Override
                          public void run() {
  
                              Log.d(Config.LOG_TAG," data.getStatus() :: "+data.getStatus());
                              int muID;
                              if(NiramaiMythriApplication.getDefaultInt(UNINVERSAL_MUID,mContext) != 0)
                              {
                                  muID =  NiramaiMythriApplication.getDefaultInt(UNINVERSAL_MUID,mContext);
                              }else
                              {
                                  muID =  LoggedInUser.Users.getDetails().getMu().get(0).getId();
                              }
                              getPatientDetails(itemView.getContext(), data.getStatus(),muID ,data.getNiramaiId(),data.getPatientId(), itemView);
                              progBar.setVisibility(View.GONE);
  
  
                          }
                      },500);
  
  
  
                  }
              });
  
  
              TextView patientID = (TextView) itemView.findViewById(R.id.patientID);
              TextView scandate = (TextView) itemView.findViewById(R.id.scanDate);
  
              try {
                  scandate.setText(oudSdf.format(inSdf.parse(data.getScanDate())));
              } catch (ParseException e) {
                  e.printStackTrace();
              }
              patientID.setText(data.getPatientId());
          }
  
  
          AvailablePatientsAdapter getPatientBinding(){
              return this.mPatientBinding;
          }
  
      }
  
  
      public AvailablePatientsAdapter(Context c, @Nullable List&lt;PatientData&gt; p){
          mContext=c;
          patients = p;
          setHasStableIds(true);
          progressDialog = new ProgressDialog(mContext);
          progressDialog.setTitle("Please wait");
          progressDialog.setMessage("Loading...");
          progressDialog.setCancelable(false);
      }
  
      @Override
      public AvailablePatientListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.available_patient_list, parent, false);
          mContext = parent.getContext();
          progBar = new ProgressBar(parent.getContext());
          return new AvailablePatientListViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(AvailablePatientListViewHolder holder, int position) {
  //        Log.e("ADAPTER","pos:"+position );
          final PatientData p = patients.get(position);
          holder.bind(p);
          holder.setIsRecyclable(false);
  
      }
  
      @Override
      public int getItemCount() {
          return patients.size();
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public int getItemViewType(int position) {
          return position;
      }
  
  
      public void setPatientList(List&lt;PatientData&gt; p, Boolean isPendingActivity){
          isPending = isPendingActivity;
          patients = p;
          notifyDataSetChanged();
      }
  
      // Dharam
       public  void clickOnRecyclerViewItem(boolean click){
          clicked = click;
      }
  
      private static void getPatientDetails(final Context context, final String status, int muID, String niramaiID, String pID, final View itemView){
          if(!progressDialog.isShowing()) {
              progressDialog.show();
          }
  
          ApiInterface mApiService = RetrofitFactory.getInterfaceService();
          Log.d(Config.LOG_TAG,"Call Start muID in Av Report :: "+muID+" niramaiID :: "+niramaiID+" pID :: "+pID);
          repStatus = status;
          mApiService.getPatientReportData(muID,niramaiID,pID).enqueue(new Callback&lt;ReportData&gt;() {
              @Override
              public void onResponse(Call&lt;ReportData&gt; call, Response&lt;ReportData&gt; response) {
                  patData =  response.body();
                  Log.d(Config.LOG_TAG,"patData status color "+ patData);
  //                progBar.setVisibility(View.VISIBLE);
                  viewPatHandler.sendEmptyMessage(1);
              }
  
  
              @Override
              public void onFailure(Call&lt;ReportData&gt; call, Throwable t) {
  //                itemView.setClickable(true);
                  Log.e(Config.LOG_TAG,"An getPatientDetails Error Occured: "+t.getMessage());
              }
          });
      }
  
      private static void getexaminationtable(String niramaiId) {
          ApiInterface mApiService = RetrofitFactory.getInterfaceService();
          Log.d(Config.LOG_TAG,"getexaminationtable Start");
          if(!progressDialog.isShowing()) {
              progressDialog.show();
          }
          mApiService.getExaminationTable(niramaiId).enqueue(new Callback&lt;List&lt;CBEData&gt;&gt;() {
              @Override
              public void onResponse(Call&lt;List&lt;CBEData&gt;&gt; call, Response&lt;List&lt;CBEData&gt;&gt; response) {
                  Log.d(Config.LOG_TAG, "Response Body :: "+response.body());
                  if(response.body() != null &amp;&amp; response.body().size()&gt;=1) {
                      viewPatHandler.sendEmptyMessage(2);
                  }
              }
  
              @Override
              public void onFailure(Call&lt;List&lt;CBEData&gt;&gt; call, Throwable t) {
                  Log.e(Config.LOG_TAG,"An getexaminationtable Error Occured: "+t.getMessage());
              }
          });
      }
  
      private static void getsegmentationtable(String niramaiId) {
          ApiInterface mApiService = RetrofitFactory.getInterfaceService();
          Log.d(Config.LOG_TAG,"getsegmentationtable Start");
          if(!progressDialog.isShowing()) {
              progressDialog.show();
  
          }
          mApiService.getSegmentationTable(niramaiId).enqueue(new Callback&lt;Object&gt;() {
              @Override
              public void onResponse(Call&lt;Object&gt; call, Response&lt;Object&gt; response) {
                  response.body();
                  viewPatHandler.sendEmptyMessage(3);
              }
  
              @Override
              public void onFailure(Call&lt;Object&gt; call, Throwable t) {
                  Log.e(Config.LOG_TAG,"An getsegmentationtable Error Occured: "+t.getMessage());
              }
          });
      }
  
      private static void getthanalysistable(String niramaiId) {
          ApiInterface mApiService = RetrofitFactory.getInterfaceService();
          Log.d(Config.LOG_TAG,"getthanalysistable Start");
          if(!progressDialog.isShowing()) {
              progressDialog.show();
          }
          mApiService.getthanAlysisTable(niramaiId).enqueue(new Callback&lt;Object&gt;() {
              @Override
              public void onResponse(Call&lt;Object&gt; call, Response&lt;Object&gt; response) {
                  response.body();
                  viewPatHandler.sendEmptyMessage(4);
              }
  
              @Override
              public void onFailure(Call&lt;Object&gt; call, Throwable t) {
                  Log.e(Config.LOG_TAG,"An getthanalysistable Error Occured: "+t.getMessage());
              }
          });
      }
  }
  </code></pre>
  
  <p>Here is my Activity <strong>AvailablePateint.class</strong> 
  can you please let me know also why is it occurring each time while scrolling each time.</p>
  
  <pre><code>public class AvailablePatients extends Activity {
  
  
      @BindView(R.id.patientsSwipeView) SwipeRefreshLayout swipeContainer;
      @BindView(R.id.patientList) RecyclerView patientListView;
      @BindView(R.id.searchBox) EditText searchBox;
  
      private Context context;
      private boolean clicked;
      static String MY_PREFS_NAME = "NIRAMAI_PREFERENCE";
      String LOG_TAG = "Niramai";
      ApiInterface mApiService;
  
      List&lt;PatientData&gt; allPatientData;
      List&lt;PatientData&gt; displayPatientData;
      List&lt;PatientData&gt; filteredPatientData;
      List&lt;PatientData&gt; availablePatData;
      Patients patient;
      //    List&lt;patient_&gt; patient_ = null;
      private AvailablePatientsAdapter mPA;
      private user mLoginObject;
      //    List&lt;IndividualPatient&gt; eachpatient = null;
      @BindView(R.id.drawerView)    PlaceHolderView mDrawerView;
      @BindView(R.id.drawerLayout)    DrawerLayout mDrawer;
      @BindView(R.id.toolbar_all)    Toolbar mToolbar;
  
      int muid = 1;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_final_report);
          availablePatData = new ArrayList&lt;&gt;();
          context = this;
          ButterKnife.bind(this);
          mLoginObject = LoggedInUser.Users.getDetails();
          if(mLoginObject == null)
          {
              Toast.makeText(this,"Please Login Again !!",Toast.LENGTH_LONG).show();
              Intent myIntent = new Intent(this, LoginActivity.class);
              //dharam
  
              myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK );
              ComponentName cn = myIntent.getComponent();
              Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);
              startActivity(mainIntent);
              finish();
          }
          SharedPreferences pref = getSharedPreferences("NiramaiPrefrence", Context.MODE_PRIVATE);
          if(mLoginObject != null) {
              muid = mLoginObject.getMu().get(0).getId();
          }
          mPA = new AvailablePatientsAdapter(this,new ArrayList&lt;PatientData&gt;());
          patientListView.setLayoutManager(new LinearLayoutManager(this,
                  LinearLayoutManager.VERTICAL,
                  false));
          RecyclerSectionItemDecoration sectionItemDecoration =
                  new RecyclerSectionItemDecoration(false,getResources().getDimensionPixelSize(R.dimen.recycler_section_header_height),
                          true,
                          getSectionCallback());
          patientListView.addItemDecoration(sectionItemDecoration);
          patientListView.setAdapter(mPA);
  
  
  
          searchBox.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
  
              }
  
              @Override
              public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                  displayPatientData = new ArrayList&lt;&gt;();
                  if(availablePatData==null) return;
                  for(PatientData pd : availablePatData){
  
                      if (pd.getPatientId().contains(charSequence)){
                          displayPatientData.add(pd);
                      }
                  }
                  Collections.sort(displayPatientData, new Comparator&lt;PatientData&gt;() {
                      @Override
                      public int compare(PatientData p1, PatientData p2) {
                          return p1.getPatientId().compareTo(p2.getPatientId());
                      }
                  });
  
                  mPA.setPatientList(displayPatientData,false);
              }
  
              @Override
              public void afterTextChanged(Editable editable) {
  
              }
  
  
          });
  
          swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
              @Override
              public void onRefresh() {
                  swipeContainer.setRefreshing(true);
                  if(NiramaiMythriApplication.getDefaultInt(UNINVERSAL_MUID,AvailablePatients.this) != 0) {
                      getAllPatientDataWithRetrofit((NiramaiMythriApplication.getDefaultInt(UNINVERSAL_MUID,AvailablePatients.this)));
  
                  }else
                  {
                      getAllPatientDataWithRetrofit(muid);
  
                  }
              }
          });
  
          swipeContainer.setRefreshing(true);
          if(NiramaiMythriApplication.getDefaultInt(UNINVERSAL_MUID,AvailablePatients.this) != 0) {
              getAllPatientDataWithRetrofit((NiramaiMythriApplication.getDefaultInt(UNINVERSAL_MUID,AvailablePatients.this)));
  
          }else
          {
              getAllPatientDataWithRetrofit(muid);
  
          }
          setupDrawer();
      }
  
  
  
  
      private RecyclerSectionItemDecoration.SectionCallback getSectionCallback() {
          return new RecyclerSectionItemDecoration.SectionCallback() {
              @Override
              public boolean isSection(int position) {
                  return false;
              }
  
              @Override
              public CharSequence getSectionHeader(int position) {
                  return "Patient ";
              }
          };
      }
  
      private void availablePatData(List&lt;PatientData&gt; patData) {
  
          int j = 0;
          Log.d(Config.LOG_TAG, "size" + patData.size());
          for (int i = 0; i &lt; patData.size(); i++) {
  //            Log.d(Config.LOG_TAG, "Patient id" + patData.get(i).getPatientId());
              if (patData.get(i).getStatus().equalsIgnoreCase(getResources().getString(R.string.report_status_available)) ||
                      patData.get(i).getStatus().equalsIgnoreCase(getResources().getString(R.string.report_status_screening_done))) {
                  availablePatData.add(j,patData.get(i));
                  j++;
              }
          }
      }
  
      private void getAllPatientDataWithRetrofit(int muID) {
          mApiService = RetrofitFactory.getInterfaceService();
          Call mService = mApiService.getAllPatients(muID);
          mService.enqueue(new Callback&lt;List&lt;Patients&gt;&gt;() {
              @Override
              public void onResponse(Call&lt;List&lt;Patients&gt;&gt; call, Response&lt;List&lt;Patients&gt;&gt; response) {
                  if(response.isSuccessful()) {
                      patient= response.body().get(0);
  
                      allPatientData = patient.getPatientData();
  
                      try {
                          filteredPatientData = filterPatients(allPatientData);
                      } catch (ParseException e) {
                          e.printStackTrace();
                      }
  
                      availablePatData(filteredPatientData);
                      displayPatientData = availablePatData;
                      mPA.setPatientList(displayPatientData,false);
                      mPA.notifyDataSetChanged();
                      swipeContainer.setRefreshing(false);
  
                      Log.d(LOG_TAG,"Response string is ::: "+ patient.toString());
                  }
              }
  
              @Override
              public void onFailure(Call&lt;List&lt;Patients&gt;&gt; call, Throwable t) {
                  call.cancel();
                  swipeContainer.setRefreshing(false);
                  Log.e(LOG_TAG,"getAllPatientDataWithRetrofit process failed in response: "+t.getMessage());
              }
          });
          if(mService.isExecuted())
          {
  
          }
      }
  
      // Filters All patient to keep only single latest record of each patient id
      private List&lt;PatientData&gt; filterPatients(List&lt;PatientData&gt; allPatientData) throws ParseException {
  
          HashMap&lt;String ,Pair&lt;PatientData,Date&gt;&gt; filtered = new HashMap&lt;&gt;();
          SimpleDateFormat inSdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
          for(PatientData p : allPatientData){
              if(filtered.containsKey(p.getPatientId())){
                  Pair&lt;PatientData,Date&gt; _p = filtered.get(p.getPatientId());
                  Date d1 = _p.second;
                  Date d2 = inSdf.parse(p.getScanDate());
                  if(d2.after(d1)){
                      filtered.put(p.getPatientId(), new Pair&lt;&gt;(p, d2));
                  }
              }else{
                  if(p.getScanDate() != null)
                      filtered.put(p.getPatientId(), new Pair&lt;&gt;(p, inSdf.parse(p.getScanDate())));
              }
          }
  
  
          List&lt;Pair&lt;PatientData,Date&gt;&gt; filteredPairs = new ArrayList&lt;&gt;(filtered.values());
          Collections.sort(filteredPairs,new Comparator&lt;Pair&lt;PatientData, Date&gt;&gt;() {
              @Override
              public int compare(Pair&lt;PatientData, Date&gt; t1, Pair&lt;PatientData, Date&gt; t2) {
                  if(t1.second.after(t2.second)){
                      return -1;
                  }else if (t1.second.before(t2.second)){
                      return 1;
                  }
                  else
                      return t1.first.getPatientId().compareTo(t2.first.getPatientId());
              }
          });
          List&lt;PatientData&gt; filteredList = new ArrayList&lt;&gt;(filteredPairs.size());
  
          for(Pair&lt;PatientData,Date&gt; p : filteredPairs){
              filteredList.add(p.first);
          }
          return filteredList;
      }
  
  
  
      @Override
      protected void onResume() {
          super.onResume();
          mPA.clickOnRecyclerViewItem(true);
  
      }
  
      @Override
      public void onBackPressed() {
          super.onBackPressed();
          finish();
      }
  
      private void setupDrawer(){
          mDrawerView
                  .addView(new DrawerHeader())
                  .addView(new DrawerMenuItem(this.getApplicationContext(),1))
                  .addView(new DrawerMenuItem(this.getApplicationContext(),2))
                  .addView(new DrawerMenuItem(this.getApplicationContext(),3))
                  .addView(new DrawerMenuItem(this.getApplicationContext(),4));
  
          ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close){
              @Override
              public void onDrawerOpened(View drawerView) {
                  super.onDrawerOpened(drawerView);
              }
              @Override
              public void onDrawerClosed(View drawerView) {
                  super.onDrawerClosed(drawerView);
              }
          };
          mDrawer.addDrawerListener(drawerToggle);
          drawerToggle.syncState();
      }
  }
  </code></pre>