我正在使用带有 volley HTTP 库的 android 回收视图,但无法以适当的速度加载到 android 中。我在下面提交了一些示例代码。
RecyclerView subCategoryrecycleview;
subCategoryrecycleview = findViewById(R.id.subCategoryrecycleview);
subCategoryrecycleview.setLayoutManager(new GridLayoutManager(getContext(), Constant.GRIDCOLUMN));
private void GetCategory() {
progressBar.setVisibility(View.VISIBLE);
Map<String, String> params = new HashMap<>();
params.put(Constant.CATEGORY_ID, cateId);
categoryArrayList = new ArrayList<>();
ApiConfig.RequestToVolley(new VolleyCallback() {
@Override
public void onSuccess(boolean result, String response) {
if (result) {
try {
JSONObject object = new JSONObject(response);
if (!object.getBoolean(Constant.ERROR)) {
JSONArray jsonArray = object.getJSONArray(Constant.DATA);
Gson gson = new Gson();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Category category = new Category();
category.setId(jsonObject.getString(Constant.ID));
category.setCategory_id(jsonObject.getString(Constant.CATEGORY_ID));
category.setName(jsonObject.getString(Constant.NAME));
category.setSlug(jsonObject.getString(Constant.SLUG));
category.setSubtitle(jsonObject.getString(Constant.SUBTITLE));
category.setImage(jsonObject.getString(Constant.IMAGE));
categoryArrayList.add(category);
}
subCategoryrecycleview.setAdapter(new SubCategoryAdapter(getContext(), activity, categoryArrayList, R.layout.lyt_category_list, "sub_cate"));
progressBar.setVisibility(View.GONE);
} else {
txtnodata.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
txtnodata.setText(object.getString(Constant.MESSAGE));
}
} catch (JSONException e) {
progressBar.setVisibility(View.GONE);
e.printStackTrace();
}
}
}
}, activity, Constant.SubcategoryUrl, params, false);
}