Note that there are some explanatory texts on larger screens.

plurals
  1. POHashMap Iteration only shows last element
    primarykey
    data
    text
    <p>I'm trying to implement an expandable listview with data coming from a database. I've already tried having the data added within the codes and it works so I'm now trying to have dynamic data from the database populate the listview. </p> <p>The data is grouped in two, the main category and the member. For example if the main category is fruit, it's members may include mango, avocado, apples, etc. If animals, it may have horses, eagle, shark. The data always comes in pairs such as Animal, Horses; Animal, Eagle; Fruit, Apples. The expandable listview should appear as:</p> <p>Animal</p> <p>-- Horses</p> <p>-- Eagle</p> <p>Fruit</p> <p>-- Apples </p> <p>My code below can already determine the main group so the headers already display the main groupings of Fruit and Animal. By using </p> <pre><code>group_member.put(family_name, member_name); </code></pre> <p>I linked the member to the main category. My problem now is how to code for the iteration to group the members to the main category. So far I've already tried using iterator based on the sample codes given here in stackoverflow and from other sites however only the last elements of each group is display. I've also tried using the for-each loop bur still no success.</p> <pre><code>String json = jsonParser.makeHttpRequest(URL_COMPONENTS, "POST", params); JSONArray components = null; ArrayList&lt;HashMap&lt;String, String&gt;&gt; componentList; List&lt;String&gt; main_group = new ArrayList&lt;String&gt;(); HashMap&lt;String, String&gt; group_member = new HashMap&lt;String, String&gt;(); try { components = new JSONArray(json); if (components != null) { for (int i = 0; i &lt; components.length(); i++) { JSONObject c = components.getJSONObject(i); String family_name = c.getString(TAG_FAMILY_NAME); String member_name = c.getString(TAG_MEMBER_NAME); main_group.add(family_name); group_member.put(family_name, member_name); if (!listDataHeader.contains(main_group)) listDataHeader.add(main_group); componentList.add(group_member); } } } </code></pre> <p>Please help. Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload