Highlight for selected item in expandable list

后端 未结 11 2309
攒了一身酷
攒了一身酷 2021-01-31 21:25

I have a layout where I have an expandable list in a fragment on the left and a details fragment on the right. This all works fine.

Now I would like to indicate what

11条回答
  •  天命终不由人
    2021-01-31 21:47

    You can save the current view and change the background color of view within your click listeners:

    View currentView;
    ExpandableListView elv;
    
    elv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            if(currentView != null) {
                currentView.setBackgroundColor(Color.parseColor("#FFFFFF"));
            }
            v.setBackgroundColor(Color.parseColor("#EEEEEE"));
            currentDrawerView = view;
    
            //do something
    
            return false;
        }
    });
    elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            if(currentView != null) {
                currentView.setBackgroundColor(Color.parseColor("#FFFFFF"));
            }
            v.setBackgroundColor(Color.parseColor("#EEEEEE"));
            currentDrawerView = view;
    
            //do something
    
            return false;
        }
    });
    

提交回复
热议问题