Arraylist<Hashmap<String, String>> in a Base Class

Asked

Viewed 188 times

1

I have the following Arraylist:

ArrayList<HashMap<String, String>> menuItens = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < 6; i++){
    HashMap<String,String> hashMap = new HashMap<String,String>();
    hashMap.put("chave_" + i, "valor_" + i);
}
menuItens.add(hashMap);

Now, in the Class extending to Basedapter I intend to capture the ArrayList<HashMap<String, String>> the two values "key" and "value" to apply to a Listview.

How best to capture these two values (key and value) in order to add them in two Strings?

  • Dude, taking a quick look at your code, I didn’t understand two things. The first is, you really need a ArrayList? Not enough a HasMap, since it supports more than one element within it. The second is if this code is running correctly, since you only add the element after the for, which would add only one element in the ArrayList...

  • Hello Philip! I need an Arraylist because each Hasmap Object will have different values. While waiting for help, I described on the Internet the following way to capture the Hasmap values in Arraylist and that solved my problem: <code>String str1 = arrayList.get(position). get("chave_" + position)</code>

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.