title: LoadMore Recycler View From Api
body: <p>I have Recycler view in Android and I need to implement load more at recycler view, I searched over internet but failed to solve my problem, this is my code please help </p>
  
  <p>This is the adapter </p>
  
  <pre><code>public class NewsReycelerViewAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
      private Context context;
      List&lt;String&gt; Dates , Titles , Details , Images;
      public static String NewsDetail,NewsDate ,NewsTitle;
      public final int TYPE_NEWS = 0;
      public final int TYPE_LOAD = 1;
      private int visibleThreshold = 2;
      private int lastVisibleItem, totalItemCount;
      private boolean loading;
      private OnLoadMoreListener onLoadMoreListener;
      public NewsReycelerViewAdapter(RecyclerView recyclerView,Context context , List&lt;String&gt; stringsDate , List&lt;String&gt; stringTitles ,  List&lt;String&gt; stringDetails ,List&lt;String&gt; stringImage,final JPANewsFragment fragment) {
  
          this.context = context;
          this.Dates = stringsDate;
          this.Titles = stringTitles;
          this.Details = stringDetails;
          this.Images = stringImage;
  
          if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
  
              final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
              recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                  @Override
                  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                      super.onScrolled(recyclerView, dx, dy);
  
                      totalItemCount = linearLayoutManager.getItemCount();
                      lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
                      if (!loading &amp;&amp; totalItemCount &lt;= (lastVisibleItem + visibleThreshold)) {
                          // End has been reached
                          // Do something
                          if (onLoadMoreListener != null) {
                              onLoadMoreListener.onLoadMore();
                          }
                          fragment.getHtmlNewsData("1");
                          loading = true;
                      }
                  }
              });
          }
      }
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          LayoutInflater inflater = LayoutInflater.from(context);
  
          if(viewType==TYPE_NEWS){
              return new Item_Holder(inflater.inflate(R.layout.news_adapter_item,parent,false));
          }else{
              return new LoadHolder(inflater.inflate(R.layout.item_loading,parent,false));
          }
  
  
      }
      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
          ((Item_Holder)holder).Date.setText(Dates.get(position));
          ((Item_Holder)holder).Title.setText(Titles.get(position));
          NewsDetail = Details.get(position);
          NewsDate = Dates.get(position);
          NewsTitle = Titles.get(position);
          ((Item_Holder)holder).itemView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  ((MainActivity)context).changeFragmentMethod(new NewsDetailsFragment(),context.getResources().getString(R.string.news_details));
              }
          });
  
  
  
      }
      @Override
      public int getItemCount() {
          return Dates == null ? 0 : Dates.size();
      }
  
  
  
      //////////////////////////////////////////////////////////////////////////////////
      public class Item_Holder extends RecyclerView.ViewHolder {
          TextView Title , Date ;
          ImageView jpaThumbnail;
          public Item_Holder(View itemView) {
              super(itemView);
              Title = (TextView) itemView.findViewById(R.id.textView_title);
              Date = (TextView) itemView.findViewById(R.id.textView_date);
              jpaThumbnail = (ImageView) itemView.findViewById(R.id.thumbnail);
  
          }
      }
      static class LoadHolder extends RecyclerView.ViewHolder{
          public LoadHolder(View itemView) {
              super(itemView);
          }
      }
  
      @Override
      public int getItemViewType(int position) {
          return Dates.get(position) != null ? TYPE_NEWS : TYPE_LOAD;
      }
  
      public void setOnLoadMoreListener(OnLoadMoreListener mOnLoadMoreListener) {
          this.onLoadMoreListener = mOnLoadMoreListener;
      }
      public void setLoaded() {
          loading = false;
      }
  
  
  }
  </code></pre>
  
  <p>First api have 10 item and when user swipes, I need to load more from another page,</p>
  
  <p>and this is the code written in my main activity </p>
  
  <pre><code> newsReycelerViewAdapter = new NewsReycelerViewAdapter(recyclerViewNews,context, stringsDate, stringsTitle, stringsDetails,stringsImages,new JPANewsFragment());
                      recyclerViewNews.setLayoutManager(new LinearLayoutManager(context));
                      recyclerViewNews.setAdapter(newsReycelerViewAdapter);
                      loadingProgressBar.setVisibility(View.GONE);
                      newsReycelerViewAdapter.setLoaded();
                      newsReycelerViewAdapter.notifyDataSetChanged();
  </code></pre>
  
  <p>Please let me know how to solve this issue.</p>