Highlight for selected item in expandable list

后端 未结 11 2085
攒了一身酷
攒了一身酷 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:45

    I was having the same problem I fixed this by adding

    v.setSelected(true);
    

    here's a sample of my code :

    expandableListDetailsLevel.setChoiceMode(ExpandableListView.CHOICE_MODE_SINGLE);
            expandableListDetailsLevel
                    .setOnGroupExpandListener(new OnGroupExpandListener() {
    
                        public void onGroupExpand(int groupPosition) {
    
                            if(groupPosition!=1){
                                expandableIsThere = false;
                            }
    
                            for (int i = 0; i < len; i++) {
                                if (i != groupPosition) {
                                    expandableListDetailsLevel.collapseGroup(i);
                                }
                            }
                        }
                    });
    
            expandableListDetailsLevel
                    .setOnChildClickListener(new OnChildClickListener() {
    
                        @Override
                        public boolean onChildClick(ExpandableListView parent,
                                View v, int groupPosition, int childPosition,
                                long id) {
    
    
                            v.setSelected(true);
    
                            }
    

    my item xml

    
    
    
    
    
    
    
    

    attribute android:drawSelectorOnTop="true" in the ExpandableListView element in the xml file (not the item child or group ) like this :

    
                
    

提交回复
热议问题