Varun Vishnoi
Varun Vishnoi

Reputation: 328

Getting Element from ArrayList<HashMap<String, HashMap<String, String>>>

I am using nested collections of String and Hashmap of two strings into Arraylist and populating some data into listview using baseadapter. I want to fetch both strings from HashMap.

Code is here:

1)

ArrayList<HashMap<String, HashMap<String, String>>> Menu = new ArrayList<HashMap<String, HashMap<String, String>>>();

2)

HashMap<String,HashMap<String,String>> mainMenu = new HashMap<String, HashMap<String,String>>();

3)

 HashMap<String,String> subMenu = new HashMap<String,String>();

                for (int k = 0; k < jsonsubmenu.length(); k++) {
                    // get all values from jsonsubmenu JSONArray..
                    String submenuname = jsonsubmenu.optString(k);
                    String price = jsonpeicemenu.optString(k);

                    subMenu.put(submenuname, price);


                }

                mainMenu.put(mainmenu, subMenu);

                Menu.add(mainMenu);

4)

MenuAdapter menuAdapter = new MenuAdapter(
                        RestaurantDetails.this.getParent(), Menu);

                list.setAdapter(menuAdapter);

Above code pieces shows the meaning full flow of usage of collection. I am using below statements for picking the data from selected positions but these statements are not worth. Please suggest me how to fetch data at seleted position.

Stringn menu = Menu.get(position).get(TAG_MENUNAME);
String cost = Menu.get(position).get(TAG_PRICE);

Upvotes: 0

Views: 1964

Answers (1)

jontejj
jontejj

Reputation: 2840

I think you want:

String cost = Menu.get(position).get(TAG_MENUNAME).get(TAG_SUBMENU);

Upvotes: 2

Related Questions