There are 5 id in idList . I need to add these id to requests to requests via retrofit. Each such request should give me a unique Product.
As a result, I want to get 5 Products in the same order as id in idList , add them to the products and send them to the adapter.
Here I am a miracle, but I write an error on the loadData() inside loadData (). As I understood, calling the loadData method again within the same method is not the most correct solution.
Tell me how to do it right.
ArrayList<String> idList = new ArrayList(); //5 id товаров currentProductId = 0; // счетчик товаров, когда счетчик будет больше чем товаров в idList, //тогда добавлять товары в адаптер и выводить их. List<Products> products = new ArrayList<>(); private void loadData() { запрос, currentProductId.enqueue { if (idList != currentProductId) { products.add(response.body()); currentProductId++; loadData(); //тут ошибка, java.lang.IndexOutOfBoundsException } if (idList == currentProductId) { adapter.setItems(products); } } }
enqueuemethod hints that requests are processed in turn, you can simply try to start them in a loop, and you can add one at a time to the adapter. - woesss