JSONArray 解析在 RecyclerView 中使用 volley android



我正在尝试使用android中的volley解析RecyclerView中的JSONArray,我每页有 10 个数据,每次向下滚动recyclerview时如何调用next page url

我的 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以加载下一页数据。

将主活动替换为您的活动

//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
}

我创建接口onbottom并检查回收器视图是否在底部,然后加载更多数据。 意味着计数将首先发布到 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;


}
});

最新更新