我正在尝试使用JSONArray
中的RecyclerView
解析volley
中的android
,我每页有10个数据,当我们如何调用next page url
时每次向下滚动recyclerview
?
我的JsonArray
"data": {
"total": 146,
"per_page": 10,
"current_page": 1,
"last_page": 15,
"next_page_url": "http://www.xxxxxxxxxx.com/api/v1/auth/deal?page=2",
"prev_page_url": null,
"from": 1,
"to": 10,
"data": [
{
"id": "209",
"ref": "101hd-209",
"pid": "437",
"name": "Office For Rent",
"deal_mode": {
"id": "128",
"category_name": "Lease"
},
我的recyclerview
一次加载第一页数据,现在向下滚动我如何调用下一页page url
来加载下一页数据。
答案 0 :(得分:1)
将MainActivity替换为您的活动
//this code will be inside adapter in onBindViewHolder
if ((position+1) == dataList.size()){
Log.d(TAG, "equal");
((MainActivity) context).loadNextPage(next_page_url);
}
//this code will be in MainActivity
public void loadNextPage(String pageUrl){
//Here you make second page request
//And add second page to list
//then notify your adapter
}
答案 1 :(得分:0)
我创建了接口onbottom
并检查Recyclerview是否位于底部,然后加载更多数据。表示计数将首先发布到API中它加载第一页数据意味着count = 1然后何时再次调用onbottom
调用函数用count ++加载第二页数据
它与我面对的结构相同,这对我很好。
接口:
public interface OnBottomReachedListener {
void onBottomReached(int position);
}
适配器:
OnBottomReachedListener onBottomReachedListener;
public void setOnBottomReachedListener(OnBottomReachedListener onBottomReachedListener){
this.onBottomReachedListener = onBottomReachedListener;
}
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
final PropertyInfo propertyInfo = propertyInfoList.get(position);
if (position == propertyInfoList.size() - 1 ){
onBottomReachedListener.onBottomReached(position);
}
}
的活动:
adapter.setOnBottomReachedListener(new OnBottomReachedListener() {
@Override
public void onBottomReached(int position) {
count++;
String URl="http://www.xxxxxxxxxx.com/api/v1/auth/deal?
page="+count;
}
});