I use
SimpleExpandableListAdapter
in my
ExpandableListActivity
When user click th
Solution provided by straya is not good for Android 2.3.3. Your ExpandableListView will lost focus and click events will stop working after list is scrolled.
I was browsing around trying to find a solution to my own ExpandableListView problem. Anyway, add my 2 cents to the answer provided by adstro.
The concept is simple:
First call the getGroupCount()
function of the ExpandableList Adapter to find the number of groups
Then, loop through the groups and call the expandGroup(int GroupPos)
function of the ExpandableList View to expand each group.
The above codes should be put inside onCreate() and also the onResume() to cater for both the first creation and the return to the activity subsequently after creation.
I have done this way:
ExpandableAdpater adapter=new ExpandableAdapter(context);
expandableListView.setAdapter(adapter);
for (int i = 0; i < listResponse.size(); i++) {
expandableListView.expandGroup(i);
}
I did something similar, except I keep all the groups expanded all the time. To accomplish this, I got a handle to the listView via ExpandableListActivity.getExpandableListView() and use ExpandableListView.expandGroup (int groupPos) to expand the groups.
For your scenario, you could keep track of which group(s) is/are expanded and once the activity to loaded again, re-expand them.
Hope this helps.
One other thing...I put this code in OnCreate().
@Override
View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
ExpandableListView eLV = (ExpandableListView) parent;
eLV.expandGroup(groupPosition);
return v;
}
after that
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Toast.makeText(getApplicationContext(),listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition),Toast.LENGTH_SHORT).show();
return false;
}
});
in onResume
...
Worked for me. No problem with scrolling.
For always expanded groups, I extend SimpleExpandableListAdapter and set the group to be expanded in the getGroupView method:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
ExpandableListView eLV = (ExpandableListView) parent;
eLV.expandGroup(groupPosition);
return v;
}