我有一个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;
}
}