0
리사이클 뷰에서로드를 더 구현하는 방법은 무엇입니까? 목록에 500 개의 항목이 있지만 20 개의 항목으로 제한하려고합니다. progresbar를 더 많이로드하면 다음 20 개 항목을 보여주고 싶습니다 ... 계속 진행합니다. 내 활동에 RecyclerView에서 더 많은 부하를 구현하는 방법은 무엇입니까? 목록에 500 개의 항목이 있습니다.
, 내가 어댑터recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int total = linearLayoutManager.getItemCount();
int firstVisibleItemCount = linearLayoutManager.findFirstVisibleItemPosition();
int lastVisibleItemCount = linearLayoutManager.findLastVisibleItemPosition();
//to avoid multiple calls to loadMore() method
//maintain a boolean value (isLoading). if loadMore() task started set to true and completes set to false
if (!loading) {
if (total > 0)
if ((total - 1) == lastVisibleItemCount) {
에서 더 listiner
mDataAdapter.setOnLoadMoreListener(new OnLoadMoreListner() {
@Override
public void onLoadMore() {
//add null , so the adapter will check view_type and show progress bar at bottom
sendingproducts.add(null);
mDataAdapter.notifyItemInserted(sendingproducts.size() - 1);
handler.postDelayed(new Runnable() {
@Override
public void run() {
// remove progress item
sendingproducts.remove(sendingproducts.size() - 1);
mDataAdapter.notifyItemRemoved(sendingproducts.size());
//add items one by one
int start = sendingproducts.size();
int end = start + 20;
if(end<=sendingproducts.size()){
sendingproducts.addAll(sendingproducts.subList(start,end));
mAdapter.notifyItemInserted(sendingproducts.size());
}
mDataAdapter.setLoaded();
//or you can add all at once but do not forget to call mAdapter.notifyDataSetChanged();
}
}, 2000);
}
});
}
로드에
Call<NextUrl> call = api.getSubCatogeryProducts(url);
call.enqueue(new Callback<NextUrl>() {
@Override
public void onResponse(Call call, Response response) {
progressBar.setVisibility(View.VISIBLE);
NextUrl responseData = (NextUrl) response.body();
String displayResponse;
if (response.isSuccessful()) {
displayResponse = "";
for (int j = 0; j <20; j++) {
productAttributes = responseData.getProductInfoList().get(j).getProductBaseInfo().getProductAttributes();
sendingproducts.add(productAttributes);
}
mDataAdapter = new DataAdapter(sendingproducts, recyclerView);
progressBar.setVisibility(View.GONE);
recyclerView.setAdapter(mDataAdapter);
Toast.makeText(TestActivity.this, "loading data", Toast.LENGTH_SHORT).show();
} else {
progressBar.setVisibility(View.GONE);
Toast.makeText(TestActivity.this, "Un Successful", Toast.LENGTH_SHORT).show();
}
progressBar.setVisibility(View.GONE);
}
@Override
public void onFailure(Call call, Throwable t) {
progressBar.setVisibility(View.GONE);
Toast.makeText(DashboardActivity.context, " failed to get the data", Toast.LENGTH_LONG).show();
}
});
}
목록에 추가 제품을 받고 있어요 // 그것은 여기 충돌을 받고있다 조건에 도달하면 total-1 = lastvisibleitemcount = 20 //
onLoadMoreListener.onLoadMore();
} else
Log.e("ok","okokokokokokoko");
}
}
제발 도와주세요.
는 널 확인 차 알려 드리겠습니다 감사 나에게 도움이 –