Note that there are some explanatory texts on larger screens.

plurals
  1. POExpandableLists in Android, I want to allow only one parent list to expand at a time
    primarykey
    data
    text
    <p>I want to make only one item in the parent list expand at a time, my code for the onCreate is currently the following. (It works as I want, But the method to allow only one parent open at a time doesnt work)</p> <pre><code>public void onCreate(Bundle savedInstanceState) { try{ super.onCreate(savedInstanceState); setContentView(R.layout.main); final SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter( //FOR LEVEL 1 SCREEN this, createGroupList(), // METHOD TO CREATE PARENTLIST Creating group List. R.layout.group_row, // REF TO XML FILENAME. new String[] { "Group Item" }, // STRING ARRAY HOLDING ONE KEY THAT REF'S ALL PARENT LIST ITEMS. new int[] { R.id.row_name }, // REF TO I.D. OF PARENT XML. ID of each group item.-Data under the key goes into this TextView. createChildList(), // METHOD TO CREATE CHILD LST. childData describes second-level entries. R.layout.child_row, // XMLFILE NAME FOR CHILD LIST.Layout for sub-level entries(second level). new String[] {"Sub Item"}, // KEY FOR CHILD ITEMS IN HASHMAP. Keys in childData maps to display. new int[] { R.id.grp_child} // XML ID FOR TEXTVIEW. Data under the keys above go into these TextViews. ); setListAdapter( expListAdapter ); // setting the adapter in the list. //**THIS IS WHAT I DONT KNOW HOW TO CODE:** list = (ExpandableListView) findViewById(R.id.row_name); list.setAdapter( expListAdapter); list.setGroupIndicator(null); list.setOnGroupExpandListener(new OnGroupExpandListener() { public void onGroupExpand(int groupPosition) { int len = expListAdapter.getGroupCount(); for (int i = 0; i &lt; len; i++) { if (i != groupPosition) { list.collapseGroup(i); } } } }); }catch(Exception e){ System.out.println("Errrr +++ " + e.getMessage()); } } </code></pre> <p>I understand the above code, However, I dont use expandableListViews, Im refferncing my program to my .xml files with the layouts of the expandablelist. And so I dont know how to apply the above to my program...</p> <p>main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;ExpandableListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bkg"/&gt; &lt;TextView android:id="@+id/android:empty" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="No items"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>The method that I dont know how to apply is the following:</p> <pre><code> list = (ExpandableListView) findViewById(R.id.row_name); list.setAdapter( expListAdapter); list.setGroupIndicator(null); list.setOnGroupExpandListener(new OnGroupExpandListener() { public void onGroupExpand(int groupPosition) { int len = expListAdapter.getGroupCount(); for (int i = 0; i &lt; len; i++) { if (i != groupPosition) { list.collapseGroup(i); } } } }); </code></pre> <p>1) how do I refference the 'list' to my expandablelist activity? </p> <p>list is defined in the class as <code>private ExpandableListView list;</code></p> <p>I do not have any errors right now, But the method does not work.</p> <p>Any help is greatly appreciated!</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.
 

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