I have an post request that gives me list of ids. I have to ping multiple requests for each ids to get the item data (image, text, etc for that particular id) and populate my recycler view. What is the best way to do this?
Asked
Active
Viewed 2,098 times
0
-
But after all of this post u get the same type of items ? If yes u can use busy indicator and show data in recycler view after download all of them. Or make progress bar and if you get one item show it in recyclerView. – qubuss Dec 23 '17 at 11:37
-
download the item when recycler view is not in scrolling state – Abdul Waheed Dec 23 '17 at 11:37
3 Answers
0
Iterate the ids and make a request with in the loop based on id and you will get a response and add to array list then pass to adapter.

Dhinakaran
- 105
- 3
- 14
0
do something like this make API call once you got the list of id
for(int id : idList){
getDetailsFromId(id);
}
and on getting the response from each id add them to your common list. assuming you are using retrofit here is sample.
public void getDetailsFromId(int id){
TaskService taskService = ServiceGenerator.createService(TaskService.class);
Call<List<TaskDetails>> call = taskService.getTasks(id);
call.enqueue(new Callback<List<TaskDetails>>() {
@Override
public void onResponse(Call<List<TaskDetails>> call, Response<List<TaskDetails>> response) {
if (response.isSuccessful()) {
// tasks available add it and notify adapter
taskDetailsList.addAll(response.body());
taskDetailsAdapter.notifyDataSetChanged();
} else {
// error response, no access to resource?
}
}
@Override
public void onFailure(Call<List<TaskDetails>> call, Throwable t) {
// something went completely south (like no internet connection)
Log.d("Error", t.getMessage());
}
}
}

vikas kumar
- 10,447
- 2
- 46
- 52
-
1this will make unlimited call on rapid scroll of same item.... try to use weakRefrence with asyncTask – Sohail Zahid Apr 18 '19 at 14:34
-
need help here --> https://stackoverflow.com/questions/64495233/retrofit-call-inside-an-adapter-in-android – android dev Oct 23 '20 at 09:20
0
Use Picasso or some other equivalent to get image and normal networking library like retrofit or volley in onBindViewHolder
, but usually api returns all other details and image urls rather than just ids.

Amit Kaushik
- 642
- 7
- 13