Java Question Need a HashMap for to build a librarie for SumUp mobile paying

NeverGiveUp2

Member
Licensed User
Longtime User
Hi guys,

for my librarie i need this hashmap structure.


B4X:
 // Create a hashMap to add additional information to the transaction
  HashMap<String,String> additionalInfo = new HashMap<String, String>(3);
  additionalInfo.put("MyAppUser","[email protected]");
  additionalInfo.put("InternalUserID","334253");
  additionalInfo.put("Color","red");


Is this in b4a possiple?

Is this the right structure for a hashmap in b4a?

B4X:
Dim addi as String
addi = "{MyAppUser=,[email protected]=};{InternalUserID=,334253=};{Color=,red=}"
SU.additionalInfo1 = addi


Best regards from Germany
 

vpires

Member
Licensed User
Longtime User
for example, you can do something like this, adapted to your needs :

in B4A :

B4X:
Dim info As Map
   
    info.Initialize
    info.Put("MyAppUser","[email protected]")
    info.Put("InternalUserID","334253")
    info.Put("Color","red")

    myLibOject.someFunc(info, other Lib parameters)

In the java Lib :

B4X:
public void someFunc(Map<String, String> baMap, other parameters) {
        HashMap<String,String> additionalInfo = new HashMap<String, String>();
   
        for (Entry<?, ?> e : baMap.entrySet()) {
            additionalInfo.put((String)e.getKey(), (String)e.getValue());
        }
       
        // .....use additionalInfo as needed, it's now a java.util.HashMap
        // rest of the code   
    }

and greetings from Portugal


Nelson
 

NeverGiveUp2

Member
Licensed User
Longtime User
Hello Nelson,

thanks for your answer, i changed something and in think now ist ok.
B4X:
public HashMap<String, String> map2hashmap(Map baMap) {
            HashMap<String,String> additionalInfo = new HashMap<String, String>();
            BA.LogInfo("baMap = " + baMap);
            for (int i=0;i < baMap.getSize();i++) {
                additionalInfo.put(baMap.GetKeyAt(i).toString(), baMap.GetValueAt(i).toString());
            }
          BA.LogInfo("additionalInfo = " + additionalInfo);
          return additionalInfo;
      }

I can't test it right, because i have another problem yet.

Best regards from Germany

Roland
 

NeverGiveUp2

Member
Licensed User
Longtime User
Hello Nelson,

it works fine now.

The structure of a Hashmap<String, String> is for example

B4X:
additionalInfo = {from here=here, my Taxi=taxi(123), to there=there}

Maby somebody need that.

Thanks a lot.

Roland
 
Top