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)
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 < len; i++) {
if (i != groupPosition) {
list.collapseGroup(i);
}
}
}
});
}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}
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...
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ExpandableListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bkg"/>
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No items"/>
</LinearLayout>
The method that I dont know how to apply is the following:
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 < len; i++) {
if (i != groupPosition) {
list.collapseGroup(i);
}
}
}
});
1) how do I refference the 'list' to my expandablelist activity?
list is defined in the class as private ExpandableListView list;
I do not have any errors right now, But the method does not work.
Any help is greatly appreciated!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en