Multi-layered ExpandableListView

后端 未结 3 1747
春和景丽
春和景丽 2020-12-14 02:18

I\'m currently working on a project in which I need something like the following:

- MainGroup 1 (Expandable)
  - SubGroup 1 (Expandable)
    - SubSubGroup 1          


        
3条回答
  •  别那么骄傲
    2020-12-14 02:41

    Even though this is not the complete solution still its a 3 layered Expandable List. So its left to you how you style it.

    here is the class

    package com.custom.nagee;
    
    import android.app.ExpandableListActivity;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseExpandableListAdapter;
    import android.widget.ExpandableListView;
    import android.widget.LinearLayout;
    
    public class CustomemExpandible extends ExpandableListActivity{
        LayoutInflater inflator;
        boolean flag = true;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            inflator = LayoutInflater.from(getApplicationContext());
            setListAdapter(new MyAdapter());
        }
    
        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {
            if(flag){
                v.findViewById(childPosition).setVisibility(View.VISIBLE);
                flag = false;
                return true;
            }
            v.findViewById(childPosition).setVisibility(View.GONE);
            flag = true;
            return true;
        }
        class MyAdapter extends BaseExpandableListAdapter{
    
            @Override
            public Object getChild(int groupPosition, int childPosition) {
                return null;
            }
    
            @Override
            public long getChildId(int groupPosition, int childPosition) {
                return 0;
            }
    
            @Override
            public View getChildView(int groupPosition, int childPosition,
                    boolean isLastChild, View convertView, ViewGroup parent) {
                LinearLayout linearLayout = (LinearLayout)inflator.inflate(R.layout.group, null);
                linearLayout.getChildAt(1).setId(childPosition);
                return linearLayout;
            }
    
            @Override
            public int getChildrenCount(int groupPosition) {
                return 2;
            }
    
            @Override
            public Object getGroup(int groupPosition) {
                return null;
            }
    
            @Override
            public int getGroupCount() {
                return 2;
            }
    
            @Override
            public long getGroupId(int groupPosition) {
                return 0;
            }
    
            @Override
            public View getGroupView(int groupPosition, boolean isExpanded,
                    View convertView, ViewGroup parent) {
                return ((LinearLayout)inflator.inflate(R.layout.group, null));
            }
    
            @Override
            public boolean hasStableIds() {
                // TODO Auto-generated method stub
                return false;
            }
    
            @Override
            public boolean isChildSelectable(int groupPosition, int childPosition) {
                return true;
            }
    
        }
    }
    

    and here goes the xml file

    group.xml

    
    

    
    
    
    
    
        
        
    
        
    
        
    
    

    and this is under color folder for changing text color, its left you , you can even change the background for getting better looks.

    back.xml

    
        
        
        
        
         
    
    

    hope it works...

提交回复
热议问题