Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I run into this two days ago. Here's my solution:</p> <p>First extend <code>ExpandableListActivity</code> and override the onCreate() method like this:</p> <pre><code>public class ExpandableExample extends ExpandableListActivity { @Override public void onCreate() { super.onCreate(savedInstanceState); setListAdapter(new BaseExpandableListAdapterExample()); } } </code></pre> <p>The definition of <code>BaseExpanableListAdapterExample</code> is (inner class of <code>ExpandableExample</code>):</p> <pre><code>protected class BaseExpandableListAdapterExample extends BaseExpandableListAdapter { } </code></pre> <p>Then you need to implement <code>getChildView</code> and <code>getGroupView</code>. What I did was:</p> <pre><code>public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { View groupRow = getLayoutInflater().inflate(R.layout.group_row, null); TextView textView = (TextView) groupRow.findViewById(R.id.text_group); textView.setText(getGroup(groupPosition).toString()); return groupRow; } public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { View childRow = getLayoutInflater().inflate(R.layout.child_row, null); TextView textView = (TextView) childRow.findViewById(R.id.text_child); textView.setText(getChild(groupPosition, childPosition).toString()); return childRow; } </code></pre> <p>Then you need to define both <code>group_row.xml</code> and <code>child_row.xml</code> under <code>/res/layout/</code> directory. For example, my <code>group_row.xml</code> is as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:id="@+id/text_element" android:layout_width="fill_parent" android:layout_height="48dip" android:textSize="20sp" android:textColor="#fff" android:layout_marginLeft="48dip" android:gravity="center_vertical" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Hope it helps. Comment if you have any question.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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