简体   繁体   中英

Android Expandable ListView on expand

Is there a way to change an imageview within my group row when the group is expanded?

I am looking for a way to do this via the code.

Cheers for any tips

EDIT: This is what I am trying to use at the moment, but it does not swap the image

    private static final int[] EMPTY_STATE_SET = {};
    private static final int[] GROUP_EXPANDED_STATE_SET = {android.R.attr.state_expanded};
    private static final int [] [] GROUP_STATE_SETS = {
        EMPTY_STATE_SET, //0
        GROUP_EXPANDED_STATE_SET //1
    };

    public View getGroupView (int groupPosition,
        boolean isExpanded,
        View convertView,
        ViewGroup parent) {

        View v = getGroupView( groupPosition, isExpanded, convertView, parent);
        View ind = v.findViewById(R.id.explist_indicator);
        if(ind != null){
            ImageView indicator = (ImageView) ind;
            indicator.setVisibility( View.VISIBLE );
            int stateSetIndex = ( isExpanded ? 1:0);
            Drawable drawable = indicator.getDrawable();
            drawable.setState(GROUP_STATE_SETS[stateSetIndex]);
        }
        return v;
    }

Use a custom BaseExpandableListAdapter . Override getGroupView and use the isExpanded boolean parameter to identify when the group view is expanded (and set your ImageView accordingly).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM