2016-11-05 4 views
0

나는 내가 그에서 위의 코드를 실행하면 내가초점 문제는

mRecyclerView.setOnScrollListener(new EndlessRecyclerOnScrollListener(
      mLayoutManager) { 
     @Override 
     public void onLoadMore(int current_page) { 
      if (SolutionEnterprises.mGetRCAAcceptedListDatas.size() < 100) { 
       from = from + limit; 
       new getHomeTicketList(false).execute(); 
      } 
     } 
    }); 

다음과 같이 클래스 위의 호출 내 조각 클래스의 하나 개 endlessrecycleview 체크 코드

import android.support.v7.widget.LinearLayoutManager; 
import android.support.v7.widget.RecyclerView; 

public abstract class EndlessRecyclerOnScrollListener extends 
    RecyclerView.OnScrollListener { 
public static String TAG = EndlessRecyclerOnScrollListener.class 
     .getSimpleName(); 

private int previousTotal = 0; 
private boolean loading = true; 
private int visibleThreshold = 5; 
int firstVisibleItem, visibleItemCount, totalItemCount; 

private int current_page = 1; 

private LinearLayoutManager mLinearLayoutManager; 

public EndlessRecyclerOnScrollListener(
     LinearLayoutManager linearLayoutManager) { 
    this.mLinearLayoutManager = linearLayoutManager; 
} 

@Override 
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 
    super.onScrolled(recyclerView, dx, dy); 

    visibleItemCount = recyclerView.getChildCount(); 
    totalItemCount = mLinearLayoutManager.getItemCount(); 
    firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition(); 

    if (loading) { 
     if (totalItemCount > previousTotal) { 
      loading = false; 
      previousTotal = totalItemCount; 
     } 
    } 
    if (!loading 
      && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) { 
     // End has been reached 

     // Do something 
     current_page++; 

     onLoadMore(current_page); 

     loading = true; 
     } 
    } 

    public abstract void onLoadMore(int current_page); 
} 

아래가 anroid 내가 recycleview에서 5 항목을 스크롤하면 agian 내 웹 API를 호출하지만 괜찮습니다. 문제는 웹 API 호출이 5 번째 항목 scrooll recycleview foucs 이후 처음으로 다시 호출되어이 문제를 해결할 수있는 방법입니다.

답변

0
you need to carefully with your adapter. 

private ContractsAdapter contractListAdapter; 

private void setAdapter(final ArrayList<ContractsModel> list) { 
    if (contractListAdapter == null) { 
      contractList = new ArrayList<>(); 
      contractList.addAll(list); 
      contractListAdapter = new ContractsAdapter(this, contractList); 
      rvContracts.setAdapter(contractListAdapter); 
     } else { 
      if (isLoadMore) { 
       contractList.addAll(list); 
       contractListAdapter.notifyDataSetChanged(); 
       isLoadMore = false; 
      } else { 
       contractList.clear(); 
       contractList.addAll(list); 
       contractListAdapter.notifyDataSetChanged(); 
      } 
     } 
    }