扩展Android Expandable ListView

时间:2011-09-16 15:47:18

标签: java android

有可能在扩展群组时更改群组内的图像视图吗?

我正在寻找通过代码实现此目的的方法。

欢呼任何提示

编辑:这是我目前正在尝试使用的,但它不会交换图像

    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;
    }

1 个答案:

答案 0 :(得分:0)

使用自定义BaseExpandableListAdapter。覆盖getGroupView并使用isExpanded布尔参数来识别组视图的展开时间(并相应地设置ImageView)。