How to keep ExpandableListView in expanded status?

后端 未结 6 1619
北恋
北恋 2020-12-14 09:19

I use

SimpleExpandableListAdapter

in my

ExpandableListActivity

When user click th

相关标签:
6条回答
  • 2020-12-14 09:37

    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.

    0 讨论(0)
  • 2020-12-14 09:38

    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.

    0 讨论(0)
  • 2020-12-14 09:41

    I have done this way:

    ExpandableAdpater adapter=new ExpandableAdapter(context);
    expandableListView.setAdapter(adapter);
    
    for (int i = 0; i < listResponse.size(); i++) {
                                    expandableListView.expandGroup(i);
                                }
    
    0 讨论(0)
  • 2020-12-14 09:43

    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().

    0 讨论(0)
  • 2020-12-14 09:44
     @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.

    0 讨论(0)
  • 2020-12-14 09:50

    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;
    }
    
    0 讨论(0)
提交回复
热议问题