How to create data for expandable list adapter in a smart way
<p>Experts,</p>

<p>Below code is to get data for ExpandableListAdapter. I have problem about the <strong>List temp</strong>.</p>

<p>Let say I have below data in db:</p>

<p>Header A, Child 123,111</p>

<p>Header B, child 456,444</p>

<p>Header C, child 789,777</p>

<p>The result I expect is: </p>

<p>expListChild.put(A, 123,111); //(actual result: expListChild.put(A, 123,111,456,444,789,777)</p>

<p>expListChild.put(B, 456,444); //(actual result: expListChild.put(B, 123,111,456,444,789,777)</p>

<p>expListChild.put(C, 789,777); //(actual result: expListChild.put(C, 123,111,456,444,789,777)</p>

<p>I don't know how to do, I've been thought of use temp1, temp2, but I don't know how many rows in Cursor cHeader . </p>

<p>Could you help me please? Thanks.
I guess the problem is I don't know how to create a series of variables. </p>

<pre><code>List&lt;String&gt; expListHeader = new ArrayList&lt;&gt;();
HashMap&lt;String, List&lt;String&gt;&gt; expListChild = new HashMap&lt;&gt;();
List&lt;String&gt; temp = new ArrayList&lt;&gt;();

void xxx() {
    Cursor cHeader = db.rawQuery("XXX", null);
    cHeader.moveToFirst();
    while (cHeader.moveToNext())
    {
        String headerStr = cHeader.getString(0);
        expListHeader.add(headerStr);

        Cursor cChild = db.rawQuery("XXX", null);
        cChild.moveToFirst();
        while (cChild.moveToNext()) {
            String childStr = cChild.getString(0);
            temp.add(childStr);
        }
        cChild.close();

        expListChild.put(headerStr, temp);
    }
}
</code></pre>