title: Recylerview items that are visible are not getting updated when notifyDataSetChanged() is called
body: <p>I am having a recycler view whose vies of the items that are visible are not getting updated, when notifyDataSetChanged() is called. The items that are invisible are getting updated without any problem.</p>
  
  <p>I have seen that this has been a problem with listview as given here:
  <a href="https://stackoverflow.com/questions/19635220/listview-not-refreshing-already-visible-items">List view  not refreshing already visible items</a></p>
  
  <p>But I am not knowing what to do with recycler view.
  In my recycler view adapter I add views dynamically according to my code.</p>
  
  <p><strong>Here is my code:</strong></p>
  
  <pre><code>public class Nearby_Viewpager_Stops extends Fragment {
  
  private final String TAG = "Nearby Stops";
  View mRootview = null;
  RecyclerView mRecyclerView;
  MKLoader mProgressBar;
  Context mContext;
  TextView mNoStopsTV;
  Nearby_Stops_Adapter mStops_adapter;
  List&lt;BusArrivalPOJO&gt; mBusArrivalPOJOList = new ArrayList&lt;&gt;();
  List&lt;List&lt;BusArrivalPOJO&gt;&gt; mBusArrivalDetailsPOJOList = new ArrayList&lt;&gt;();
  LinearLayoutManager mLayoutManager;
  Handler mHandler;
  Handler mHandlerForOnStop;
  
  boolean resumed = true;
  private static final int REFRESH_TIME = 30;
  int lengthOfStopsList;
  
  boolean isNoStops_available_nearby = false;
  boolean isFirstTimeCalled;
  boolean isRunningFirstTime;
  
  
  @Override
  public void onAttach(Context context) {
      super.onAttach(context);
      mContext = context;
  }
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      if (mRootview == null) {
          mRootview = inflater.inflate(R.layout.nearby_viewpager_stops, container, false);
          mRecyclerView = (RecyclerView) mRootview.findViewById(R.id.recycler_view);
          mProgressBar = (MKLoader) mRootview.findViewById(R.id.progressBar);
          mNoStopsTV = (TextView) mRootview.findViewById(R.id.no_nearby_stops_text);
      }
  
      mLayoutManager = new LinearLayoutManager(mContext);
      mRecyclerView.setLayoutManager(mLayoutManager);
  
      mStops_adapter = new Nearby_Stops_Adapter(mBusArrivalPOJOList, mBusArrivalDetailsPOJOList);
      mRecyclerView.setItemAnimator(new DefaultItemAnimator());
      mRecyclerView.setAdapter(mStops_adapter);
  
      return mRootview;
  }
  
  
  private class GetNearbyStops extends AsyncTask&lt;Void, Void, Void&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          isNoStops_available_nearby = false;
          mProgressBar.setVisibility(View.VISIBLE);
  
          mBusArrivalPOJOList.clear();
          pos = mLayoutManager.findFirstVisibleItemPosition();
          mStops_adapter.notifyDataSetChanged();
      }
  
      @Override
      protected Void doInBackground(Void... voids) {
          String urlString = "https://api.tfl.gov.uk/StopPoint?radius=2000&amp;stopTypes=NaptanRailStation,NaptanBusCoachStation,NaptanFerryPort,NaptanPublicBusCoachTram&amp;useStopPointHierarchy=true" +
                  "&amp;modes=bus&amp;lat="+ Constants.latitude+"&amp;lon="+Constants.longitude+"&amp;categories=facility&amp;app_id=" + Constants.app_id_tfl + "&amp;app_key=" + Constants.app_key_tfl;
  
          Log.v(TAG, urlString);
          HttpURLConnection urlConnection = null;
  
          BufferedReader bufferedReader;
          String line;
          InputStream inputStream;
          StringBuilder json_result = new StringBuilder();
          try {
              System.setProperty("http.keepAlive", "false");
              URL url = new URL(urlString);
              urlConnection = (HttpURLConnection) url.openConnection();
              urlConnection.setReadTimeout(2000);
              urlConnection.setConnectTimeout(2000);
              urlConnection.setRequestMethod("GET");
  
              inputStream = new BufferedInputStream(urlConnection.getInputStream());
              bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
  
              while ((line = bufferedReader.readLine()) != null) {
                  json_result.append(line);
              }
  
          } catch (Exception e) {
              Log.e(TAG, e.getLocalizedMessage());
          } finally {
              if (urlConnection != null) {
                  urlConnection.disconnect();
              }
          }
          getDataFromJSON(json_result.toString());
          return null;
      }
  
      private void getDataFromJSON(String json) {
          try {
              JSONObject jsonObject = new JSONObject(json);
              JSONArray stopPoints = jsonObject.getJSONArray("stopPoints");
  
              if (stopPoints.length() &lt;= 20 &amp;&amp; stopPoints.length() != 0) {
                  lengthOfStopsList = stopPoints.length();
              } else if (stopPoints.length() == 0) {
                  lengthOfStopsList = 0;
                  isNoStops_available_nearby = true;
              }
              for (int i = 0; i&lt; lengthOfStopsList; i++) {
                  JSONObject jsonObject1 = stopPoints.getJSONObject(i);
                  int distance = Math.round(jsonObject1.getInt("distance")/60);
                  Double lat = jsonObject1.getDouble("lat");
                  Double lon = jsonObject1.getDouble("lon");
                  String commonName = jsonObject1.getString("commonName");
  
  
                  JSONArray lineGroup = jsonObject1.getJSONArray("lineGroup");
                  new GetBusArrivals().execute(lineGroup, new LatLng(lat, lon), distance);
  
                  String naptanID;
  
                  for (int j=0; j&lt; lineGroup.length(); j++) {
                      JSONObject  jsonObject2 = lineGroup.getJSONObject(j);
                      if (jsonObject2.has("naptanIdReference")) {
                          naptanID = jsonObject2.getString("naptanIdReference");
                          BusArrivalPOJO busArrivalPOJO = new
                                  BusArrivalPOJO(commonName, distance, new LatLng(lat, lon), naptanID);
                          mBusArrivalPOJOList.add(busArrivalPOJO);
                          getActivity().runOnUiThread(new Runnable() {
                              @Override
                              public void run() {
                                  mStops_adapter.notifyDataSetChanged();
                              }
                          });
                      }
                  }
              }
  
          } catch (JSONException e) {
              Log.e(TAG, e.getLocalizedMessage());
              if (getActivity()!=null)
                  getActivity().runOnUiThread(new Runnable() {
                  public void run() {
                      new GetNearbyStops().execute();
                  }
              });
          }
      }
  
      @Override
      protected void onPostExecute(Void aVoid) {
          super.onPostExecute(aVoid);
          if (isNoStops_available_nearby) {
              mProgressBar.setVisibility(View.GONE);
              mNoStopsTV.setVisibility(View.VISIBLE);
          } else {
              mProgressBar.setVisibility(View.VISIBLE);
              mNoStopsTV.setVisibility(View.GONE);
          }
      }
  }
  
  int pos;
  private class GetBusArrivals extends AsyncTask&lt;Object, Void, Void&gt; {
  
      /**
       * It represents the position of the first visible position of recycler view
       */
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          if (isFirstTimeCalled) {
              if (getActivity() != null)
              getActivity().runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
                      mBusArrivalDetailsPOJOList.clear();
                      mStops_adapter.notifyDataSetChanged();
                  }
              });
              isFirstTimeCalled = false;
          }
  
      }
      LatLng latLng;
      String stopID;
      int distance;
      @Override
      protected Void doInBackground(Object... strings) {
  
          JSONArray lineGroup = (JSONArray) strings[0];
          latLng = (LatLng) strings[1];
          distance = (int) strings[2];
  
  
          try {
              for (int j=0; j&lt; lineGroup.length(); j++) {
                  JSONObject  jsonObject2 = lineGroup.getJSONObject(j);
                  if (jsonObject2.has("naptanIdReference")) {
                      stopID = jsonObject2.getString("naptanIdReference");
                      String urlString = "https://api.tfl.gov.uk/StopPoint/"+stopID+"/Arrivals?app_id="
                              + Constants.app_id_tfl + "&amp;app_key=" + Constants.app_key_tfl;
                      HttpURLConnection urlConnection = null;
  
                      BufferedReader bufferedReader;
                      String line;
                      InputStream inputStream;
                      StringBuilder json_result = new StringBuilder();
                      try {
                          Log.v(TAG, urlString);
                          System.setProperty("http.keepAlive", "false");
                          URL url = new URL(urlString);
                          urlConnection = (HttpURLConnection) url.openConnection();
                          urlConnection.setReadTimeout(2000);
                          urlConnection.setConnectTimeout(2000);
                          urlConnection.setRequestMethod("GET");
  
                          inputStream = new BufferedInputStream(urlConnection.getInputStream());
                          bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
  
                          while ((line = bufferedReader.readLine()) != null) {
                              json_result.append(line);
                          }
                          List&lt;BusArrivalPOJO&gt;  busArrivalPOJOs = getDataFromJSON(json_result.toString(), latLng, distance);
                          if (busArrivalPOJOs != null) {
                              mBusArrivalDetailsPOJOList.add(busArrivalPOJOs);
                              Log.v("length", "leng"+mBusArrivalDetailsPOJOList.size());
                              if (getActivity() != null) {
                                  getActivity().runOnUiThread(new Runnable() {
                                      @Override
                                      public void run() {
                                          if (mProgressBar.getVisibility() == View.VISIBLE)
                                              mProgressBar.setVisibility(View.GONE);
  
                                          if (mBusArrivalDetailsPOJOList.size() &lt; 5) {
                                              mRecyclerView.setAdapter(mStops_adapter);
                                          } else
                                                 mStops_adapter.notifyDataSetChanged();
                                      }
                                  });
                              }
  
  
  
                          }
  
                      } catch (Exception e) {
                              j= j-1;
                      } finally {
                          if (urlConnection != null) {
                              urlConnection.disconnect();
                          }
                      }
                  }
              }
          } catch (JSONException e) {
              Log.e(TAG, e.getLocalizedMessage());
          }
  
  
  
          return null;
      }
  
      private List&lt;BusArrivalPOJO&gt; getDataFromJSON(String json, LatLng latLng, int distance) {
          List&lt;BusArrivalPOJO&gt; busArrivalPOJOList = new ArrayList&lt;&gt;();
          try {
              Log.v(TAG,  json);
              JSONArray jsonArray = new JSONArray(json);
              for (int i=0; i&lt; jsonArray.length(); i++) {
                  JSONObject jsonObject = jsonArray.getJSONObject(i);
  
                  if (jsonObject.has("exceptionType") &amp;&amp; jsonObject.getString("exceptionType").contentEquals("EntityNotFoundException")) {
                     return null;
                  } else {
                      String lineName = jsonObject.getString("lineName");
                      String platformName = jsonObject.getString("platformName");
                      String destinationName = jsonObject.getString("destinationName");
                      int timeToArrivalToStation = jsonObject.getInt("timeToStation");
                      String stationName = jsonObject.getString("stationName");
                      String naptanId = jsonObject.getString("naptanId");
  
                      BusArrivalPOJO busArrivalPOJO = new BusArrivalPOJO(lineName, platformName, destinationName,
                              timeToArrivalToStation, stationName, latLng, distance, naptanId);
                      busArrivalPOJOList.add(busArrivalPOJO);
                  }
              }
  
          } catch (JSONException e) {
              Log.e(TAG, e.getLocalizedMessage());
          }
          return busArrivalPOJOList;
      }
  
      @Override
      protected void onPostExecute(Void aVoid) {
          super.onPostExecute(aVoid);
  
  
          if (pos&lt; mBusArrivalPOJOList.size()-5 &amp;&amp; mBusArrivalPOJOList.size()-5 == mBusArrivalDetailsPOJOList.size()
                  || mBusArrivalDetailsPOJOList.size() == mBusArrivalPOJOList.size()) {
          }
  
          if (MainActivity.menuItem != null &amp;&amp; MainActivity.menuItem.getActionView() != null) {
              MainActivity.menuItem.getActionView().clearAnimation();
              MainActivity.menuItem.setActionView(null);
          }
      }
  
  }
  
  
  @Override
  public void onResume() {
      super.onResume();
  
      mHandler = new Handler();
      resumed = true;
      isRunningFirstTime = true;
  
      mHandler.postDelayed(new Runnable() {
          @Override
          public void run() {
              isFirstTimeCalled = true;
              new GetNearbyStops().execute();
  
              mHandler.postDelayed(this, REFRESH_TIME * 1000);
          }
      }, 1000);
  }
  }
  </code></pre>
  
  <p><strong>Here is the code for my recycler view adapter:</strong></p>
  
  <pre><code>class Nearby_Stops_Adapter extends RecyclerView.Adapter {
  
  private List&lt;List&lt;BusArrivalPOJO&gt;&gt; mBusArrivalPOJOListFullDetails = new ArrayList&lt;&gt;();
  private List&lt;BusArrivalPOJO&gt; mBusArrivalPOJOList = new ArrayList&lt;&gt;();
  
  Context mContext;
  private LinearLayout mLinearLayout;
  private static HashSet&lt;String&gt; isRemainingTimesOpen = new HashSet&lt;&gt;();
  
  private final String TAG = "NearbyStopsAda";
  
  Nearby_Stops_Adapter(List&lt;BusArrivalPOJO&gt; busArrivalPOJOList,List&lt;List&lt;BusArrivalPOJO&gt;&gt; busArrivalPOJOList1 ) {
      mBusArrivalPOJOList = busArrivalPOJOList;
      mBusArrivalPOJOListFullDetails = busArrivalPOJOList1;
  }
  
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View rootView =  LayoutInflater.from(parent.getContext())
              .inflate(R.layout.nearby_stops_adapter,parent,false);
      mContext = parent.getContext();
  
      mLinearLayout = (LinearLayout) rootView.findViewById(R.id.linear_layout);
      TextView mStationName = (TextView) rootView.findViewById(R.id.stationName);
      mStationName.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
  
      MKLoader progressBar = (MKLoader) rootView.findViewById(R.id.progressBar);
  
      TextView timeToWalkToStation = (TextView) rootView.findViewById(R.id.timeToTravel);
      CardView cardView = (CardView) rootView.findViewById(R.id.cardView);
  
      return new Nearby_Stops_Adapter.ViewHolder(rootView, mStationName, timeToWalkToStation, cardView, progressBar);
  }
  
  @Override
  public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
  
      if (mBusArrivalPOJOList.size() &gt; 0) {
          ((ViewHolder) holder).stationNameTV.setText(mBusArrivalPOJOList.get(position).getStationName());
          String time = mBusArrivalPOJOList.get(position).getTimeToWalkToStation() + " min";
          ((ViewHolder) holder).timeToWalkToStation.setText(time);
      }
  
      if (mBusArrivalPOJOListFullDetails.size()&gt;0) {
          mLinearLayout.removeAllViews();
  
          for (int a=0; a&lt; mBusArrivalPOJOListFullDetails.size() ;a++) {
              if (mBusArrivalPOJOList.get(position).getStationID()
                      .contentEquals(mBusArrivalPOJOListFullDetails.get(a).get(0).getStationID())) {
  
                  if (!mBusArrivalPOJOListFullDetails.get(a).get(0).getPlatformName().contentEquals("null"))
                      if (!((ViewHolder) holder).stationNameTV.getText().toString().contains("::"))
                          ((ViewHolder) holder).stationNameTV.append(" :: "+mBusArrivalPOJOListFullDetails.get(a).get(0).getPlatformName());
  
                  for (int j=0; j&lt; mBusArrivalPOJOListFullDetails.get(a).size() ;j++) {
                      Collections.sort(mBusArrivalPOJOListFullDetails.get(a), new Comparator&lt;BusArrivalPOJO&gt;() {
                          @Override
                          public int compare(BusArrivalPOJO busArrivalPOJO, BusArrivalPOJO t1) {
                              return busArrivalPOJO.getTimeToArrival() - t1.getTimeToArrival();
                          }
                      });
                  }
  
                  Set&lt;String&gt; uniqueBusNamesSet  = new HashSet&lt;&gt;();
                  for (int m = 0; m&lt; mBusArrivalPOJOListFullDetails.get(a).size() ;m++) {
                      uniqueBusNamesSet.add(mBusArrivalPOJOListFullDetails.get(a).get(m).getBusName());
                  }
  
                  ArrayList&lt;Multimap&lt;String, Integer&gt;&gt; allBusesForParticularStation = new ArrayList&lt;&gt;();
                  for (String key: uniqueBusNamesSet) {
                      Multimap&lt;String, Integer&gt; busWithTimes = ArrayListMultimap.create();
                      for (int s=0; s&lt; mBusArrivalPOJOListFullDetails.get(a).size() ;s++) {
                          if (key.contentEquals(mBusArrivalPOJOListFullDetails.get(a).get(s).getBusName())) {
                              busWithTimes.put(key +"::"+ mBusArrivalPOJOListFullDetails.get(a).get(s).getDestinationName()
                                      , mBusArrivalPOJOListFullDetails.get(a).get(s).getTimeToArrival());
                          }
                      }
                      allBusesForParticularStation.add(busWithTimes);
                  }
  
                  ((ViewHolder) holder).progressBar.setVisibility(View.GONE);
                  for (int t=0 ; t&lt; allBusesForParticularStation.size() ;t++) {
                      Multimap&lt;String,  Integer&gt; map = allBusesForParticularStation.get(t);
                      for (String key: map.keySet()) {
                          List&lt;Integer&gt; values = new ArrayList&lt;&gt;(map.get(key));
  
                          RelativeLayout relativeLayout = new RelativeLayout(mContext);
                          relativeLayout.setPadding(16, 16, 16, 16);
  
                          LinearLayout linearLayoutForBusName = new LinearLayout(mContext);
                          linearLayoutForBusName.setOrientation(LinearLayout.VERTICAL);
  
                          final TextView busNameTV = new TextView(mContext);
                          busNameTV.setText(key.split("::")[0]);
                          busNameTV.setTypeface(Typeface.create("sans-serif-normal", Typeface.NORMAL));
                          busNameTV.setTextColor(ContextCompat.getColor(mContext,R.color.colorTextPrimary));
  
                          final TextView destinationNameTV = new TextView(mContext);
                          destinationNameTV.setText(key.split("::")[1]);
                          destinationNameTV.setTextSize(12);
                          destinationNameTV.setTextColor(ContextCompat.getColor(mContext,R.color.colorTextSecondary));
  
                          linearLayoutForBusName.addView(busNameTV);
                          linearLayoutForBusName.addView(destinationNameTV);
  
                          LinearLayout linearLayoutForTimes = new LinearLayout(mContext);
                          linearLayoutForTimes.setOrientation(LinearLayout.VERTICAL);
  
                          RelativeLayout timeRelativeLayout = new RelativeLayout(mContext);
                          timeRelativeLayout.setId(R.id.time_relativeLayout_id);
  
                          LinearLayout timeArrowLinearLayout = new LinearLayout(mContext);
                          timeArrowLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
                          timeArrowLinearLayout.setId(R.id.time_id);
                          timeArrowLinearLayout.setGravity(Gravity.CENTER_VERTICAL);
                          timeArrowLinearLayout.setPadding(6,6,6,6);
  
                          RelativeLayout.LayoutParams timeArrowLP = new RelativeLayout.LayoutParams(
                                  ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                          timeArrowLP.addRule(RelativeLayout.RIGHT_OF, R.id.time_tv);
                          timeArrowLP.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                          timeArrowLinearLayout.setLayoutParams(timeArrowLP);
  
  
                          //Recent Time text view
                          TextView timeTV = new TextView(mContext);
                          int timeSec = values.get(0);
                          int timeInMin = Math.round(timeSec / 60);
                          if (timeInMin == 0) {
                              String timeText = "due";
                              timeTV.setText(timeText);
                          } else {
                              String timeInMinText = timeInMin + " min";
                              timeTV.setText(timeInMinText);
                          }
                          timeTV.setTextColor(ContextCompat.getColor(mContext, R.color.textColorAccent));
                          timeTV.setPadding(0,0,16,0);
  
                          final TextView remainingTimesTV = new TextView(mContext);
                          remainingTimesTV.setTextColor(ContextCompat.getColor(mContext, R.color.colorTextSecondary));
                          remainingTimesTV.setTextSize(11);
                          remainingTimesTV.setVisibility(View.GONE);
  
                          for (int l=1; l&lt; values.size() &amp;&amp; l &lt; 4; l++) {
                              String tempTime;
                              if (l == 3 || l == values.size() - 1) {
                                  tempTime = values.get(l) / 60 + " min";
                              }
                              else
                                  tempTime = values.get(l)/60 + " min, ";
                              remainingTimesTV.append(tempTime);
                          }
  
                          RelativeLayout.LayoutParams remainingTimeLayoutParams = new RelativeLayout.LayoutParams
                                  (ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                          remainingTimeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                          remainingTimeLayoutParams.addRule(RelativeLayout.BELOW, R.id.time_id);
                          remainingTimesTV.setLayoutParams(remainingTimeLayoutParams);
  
                          timeArrowLinearLayout.addView(timeTV);
  
                          if (values.size() &gt; 1) {
  
                              //Down arrow button
                              final ImageView imageButton = new ImageView(mContext);
                              imageButton.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.arrow_down));
  
                              if (isRemainingTimesOpen != null) {
                                  for (String openedRowKey : isRemainingTimesOpen) {
                                      if (openedRowKey.contains(busNameTV.getText().toString()) &amp;&amp;
                                              openedRowKey.contains(destinationNameTV.getText().toString()) &amp;&amp;
                                              openedRowKey.contains(((ViewHolder) holder).stationNameTV.getText().toString())) {
                                          remainingTimesTV.setVisibility(View.VISIBLE);
                                          imageButton.setImageResource(R.drawable.arrow_top);
                                      }
                                  }
                              }
  
                              timeArrowLinearLayout.setOnClickListener(new View.OnClickListener() {
                                  @Override
                                  public void onClick(View view) {
                                      if (remainingTimesTV.getVisibility() == View.GONE) {
                                          isRemainingTimesOpen.add(busNameTV.getText().toString()
                                                  +destinationNameTV.getText().toString()
                                                  +(((ViewHolder) holder).stationNameTV.getText().toString()));
                                          remainingTimesTV.setVisibility(View.VISIBLE);
                                          imageButton.setImageResource(R.drawable.arrow_down);
                                          imageButton.animate().rotation(180).start();
  
                                      } else {
                                          remainingTimesTV.setVisibility(View.GONE);
                                          imageButton.setImageResource(R.drawable.arrow_top);
                                          imageButton.animate().rotation(-180).start();
                                      }
                                  }
                              });
  
                              timeArrowLinearLayout.addView(imageButton);
                          }
  
                          RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                                  ViewGroup.LayoutParams.WRAP_CONTENT);
                          layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                          layoutParams2.addRule(RelativeLayout.CENTER_VERTICAL);
                          timeRelativeLayout.setLayoutParams(layoutParams2);
  
                          timeRelativeLayout.addView(timeArrowLinearLayout);
                          timeRelativeLayout.addView(remainingTimesTV);
  
  
                          View horLine = new View(mContext);
                          RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                  1);
                          horLine.setLayoutParams(layoutParams3);
                          horLine.setBackgroundColor(ContextCompat.getColor(mContext, R.color.horizontal_line));
                          horLine.setPadding(0,5,0,5);
  
                          relativeLayout.addView(linearLayoutForBusName);
                          relativeLayout.addView(timeRelativeLayout);
                          ((ViewHolder) holder).cardView.setOnClickListener(new View.OnClickListener() {
                              @Override
                              public void onClick(View view) {
  
                              }
                          });
  
                          mLinearLayout.addView(relativeLayout);
  
                          if (t &lt; uniqueBusNamesSet.size()-1) {
                              mLinearLayout.addView(horLine);
                          }
                      }
                  }
              }
          }
      }
  }
  
  @Override
  public int getItemViewType(int position) {
      return position;
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  
  @Override
  public int getItemCount() {
      return mBusArrivalPOJOList.size();
  }
  
  private class ViewHolder extends RecyclerView.ViewHolder {
      TextView stationNameTV;
      TextView timeToWalkToStation;
      CardView cardView;
      MKLoader progressBar;
  
      ViewHolder(View view, TextView stationNameTV, TextView timeToWalkToStation, CardView cardView,
                 MKLoader progressBar) {
          super(view);
          this.stationNameTV = stationNameTV;
          this.timeToWalkToStation = timeToWalkToStation;
          this.cardView = cardView;
          this.progressBar = progressBar;
      }
  }
  }
  </code></pre>