Click here to Skip to main content
15,891,184 members

How to combine result of two different API calls to a hashmap

Rahul Ramakrishnan asked:

Open original thread
I've two api's one for retrieving list items and the other for retrieving Images based on the first api id. I'm able fetch the items and display it in recyclerview but the problem is that only for the last item in the list the image is shown

What I have tried:

First api call method that retrieves the list items and sets the items to HashMap<string,string>
Java
for (RetrieveItemCatalogListByItemCategoryListItem items : response.body()) {
              combinedHashMap = new HashMap<>();
              combinedHashMap.put("ID", String.valueOf(items.getId()));
              combinedHashMap.put("SUPPLIER_ID", String.valueOf(items.getiSupplierID()));
              combinedHashMap.put("SUPPLIER_STORE_NAME", items.getsSupplierStoreName());
              combinedHashMap.put("ITEM_CATEGORY_ID", String.valueOf(items.getiItemCategoryID()));
              combinedHashMap.put("ITEM_CATEGORY", items.getsItemCategory());
              combinedHashMap.put("PRODUCT_TYPE_ID", String.valueOf(items.getiProductTypeID()));
              combinedHashMap.put("PRODUCT_TYPE", items.getsProductType());
              combinedHashMap.put("AVAILABILITY_ID", String.valueOf(items.getiAvailabilityID()));
              combinedHashMap.put("AVAILABILITY", items.getsAvailability());
              combinedHashMap.put("CURRENT_STOCK", items.getsCurrentStock());
              combinedHashMap.put("CURRENT_PRICE", items.getsCurrentPrice());
              combinedHashMap.put("RETURN_POLICY_ID", String.valueOf(items.getiReturnPolicyID()));
              combinedHashMap.put("RETURN_POLICY", items.getsReturnPolicy());
              combinedHashMap.put("PRODUCT_NAME", items.getsProductName());
              combinedHashMap.put("PRODUCT_SERVICE_NAME", items.getsProductServiceName());
              combinedHashMap.put("PRODUCT_DESCRIPTION", items.getsProductDescription());
              combinedHashMap.put("WORKFLOW_STATUS_ID", String.valueOf(items.getiWorkflowStatusID()));
              combinedHashMap.put("WORKFLOW_STATUS", items.getsWorkflowStatus());
              combinedHashMap.put("CREATE_DATE", items.getsCreateDate());
              combinedHashMap.put("UPDATE_DATE", items.getsUpdateDate());
// Method to get Image based on ID
              retrieveImageSource(items.getiSupplierID());
// List<HashMap<String,String>> 
              productMap.add(combinedHashMap);

            }


Second API method to retrieve image
Java
for (RetrieveListBySourceTypeListItem items : response.body().getResult()) {
            List<HashMap<String, String>> fileMap = new ArrayList<>();
            combinedHashMap.put("FILE_NAME", items.getsFileName());
            combinedHashMap.put("SOURCE_ID", String.valueOf(items.getiSourceID()));
            combinedHashMap.put("SOURCE_TYPE_ID", String.valueOf(items.getiSourceTypeID()));


          }

          Log.d("Combined_Items", productMap.toString());
          binding.selectedItemsList.setAdapter(new SearchProductResultAdapter(SearchProductResultActivity.this, productMap, new SearchProductResultAdapter.OnItemClick() {
            @Override
            public void onClick(View view, HashMap<String, String> combinedListItem) {
              if (view.getId() == R.id.layoutItem) {
                String id = combinedListItem.get("ID");
                startActivity(new Intent(getApplicationContext(), ShoppingCartActivity.class)
                    .putExtra("ID", combinedListItem.get("ID")));
              }
            }
          }));
Tags: Android

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900