activity 布局
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--需要加载的recyclerVoice-->
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/popup_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<android.support.v7.widget.RecyclerView
android:id="@+id/sort_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.5"
android:background="#000000" />
</LinearLayout>
//recyclerView 初始化 myAdapter = new HolidaySortAdapter(R.layout.item_holiday_sort, context); recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); myAdapter.setOnLoadMoreListener(this, recyclerView);
//加载 @Override public void onLoadMoreRequested() { page++; postOkgo(1); myAdapter.loadMoreComplete();
}
private void postOkgo(final int tag) { showProgressDialog(); JSONObject jsonObject = new JSONObject(); try { jsonObject.put("cityCode", cityCode); jsonObject.put("kindCode", typeCode); jsonObject.put("keyWords", keyWords); jsonObject.put("soft", soft); jsonObject.put("longitude", MyApp.getApplication().getCurrentLongitude()); jsonObject.put("latitude", MyApp.getApplication().getCurrentLatitude()); jsonObject.put("page", page); jsonObject.put("pageSize", 1); } catch (JSONException e) { e.printStackTrace(); } OkGoHttp.getInstance().okGoPost(context, Constants.GetVacationPoi, jsonObject, new OkGoHttp.OnNetResultListener() { @Override public void onSuccessful(String resultStr) { closeProgressDialog(); HolidaySortData data = gson.fromJson(resultStr, HolidaySortData.class); sortDatas = data.getResult().getData(); if (tag == 0) { myAdapter.setNewData(sortDatas); recyclerView.setAdapter(myAdapter); mRefreshLayout.finishRefresh(); // myAdapter.setEnableLoadMore(true); } //加载 if (tag == 1) { if (data.getResult().getData().size() == 0) { myAdapter.loadMoreEnd(); } else { for (int i = 0; i < data.getResult().getData().size(); i++) { myAdapter.addData(data.getResult().getData().get(i));
}
}
mRefreshLayout.setEnableRefresh(true);
}
}
@Override
public void onFailure(String errMsg) {
}
});
}