用于ExpandableHeightGridview的setOnItemclicklistener

时间:2018-06-10 14:05:27

标签: android gridview

我有一个ExpandableHeightGridview类,下面提供了代码,我在这个类中定义了一个对象来初始化我的GridView。问题是如何为它定义.setOnItemclicklistener

这是ExpandableHeightGridview的类:

public class ExpandableGridview extends GridView
{
    boolean expanded = false;
    private ItemClickListener clickListener;


    public ExpandableGridview(Context context)
    {
        super(context);
    }

    public ExpandableGridview(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public ExpandableGridview(Context context, AttributeSet attrs,
                                    int defStyle)
    {
        super(context, attrs, defStyle);
    }

    public boolean isExpanded()
    {
        return expanded;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        // HACK! TAKE THAT ANDROID!
        if (isExpanded())
        {
            int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
                    MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();
        }
        else
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
    public void setExpanded(boolean expanded) {
        this.expanded = expanded;
    }

}

0 个答案:

没有答案