Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this,</p> <p><strong>main.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="ExpandableListViewSample" /&gt; &lt;ExpandableListView android:id="@+id/ExpandableListView" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" &gt; &lt;/ExpandableListView&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>ExpList.java</strong></p> <pre><code>package com.example.android.photoalbum; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.ExpandableListView.OnGroupClickListener; import android.widget.SimpleExpandableListAdapter; public class ExpList extends Activity { private static final String KEY1 = "GROUP"; private static final String KEY2 = "CHILD"; private String[] GROUPS = { "Group1", "Group2", "Group3" }; private String[][][] CHILDREN = { { { "Child11", "Text11" } }, { { "Child21", "Text21" }, { "Child22", "Text22" } }, { { "Child31", "Text31" }, { "Child32", "Text32" }, { "Child33", "Text33" } }, }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); List&lt;Map&lt;String, String&gt;&gt; groupData = new ArrayList&lt;Map&lt;String, String&gt;&gt;(); List&lt;List&lt;Map&lt;String, String&gt;&gt;&gt; childData = new ArrayList&lt;List&lt;Map&lt;String, String&gt;&gt;&gt;(); for (int i = 0; i &lt; GROUPS.length; i++) { Map&lt;String, String&gt; curGroupMap = new HashMap&lt;String, String&gt;(); groupData.add(curGroupMap); curGroupMap.put(KEY1, GROUPS[i]); curGroupMap.put(KEY2, ""); List&lt;Map&lt;String, String&gt;&gt; children = new ArrayList&lt;Map&lt;String, String&gt;&gt;(); if (CHILDREN.length &gt; i) { for (int j = 0; j &lt; CHILDREN[i].length; j++) { Map&lt;String, String&gt; curChildMap = new HashMap&lt;String, String&gt;(); children.add(curChildMap); curChildMap.put(KEY1, CHILDREN[i][j][0]); curChildMap.put(KEY2, CHILDREN[i][j][1]); } } childData.add(children); } ExpandableListAdapter adapter = new SimpleExpandableListAdapter(this, groupData, android.R.layout.simple_expandable_list_item_1, new String[] { KEY1, KEY2 }, new int[] { android.R.id.text1, android.R.id.text2 }, childData, android.R.layout.simple_expandable_list_item_2, new String[] { KEY1, KEY2 }, new int[] { android.R.id.text1, android.R.id.text2 }); ExpandableListView listView = (ExpandableListView) findViewById(R.id.ExpandableListView); listView.setAdapter(adapter); listView.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { return false; } }); listView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { return false; } }); } } </code></pre>
    singulars
    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. VO
      singulars
      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