I implemented an expandedGridView like this Kishanjvaghela's github example or the answer of Raj008 in stack Overflow.
It works fine, but I wonder why does it need to call super()
in the constructor
public class ExpandableHeightGridView extends GridView {
boolean expanded = false;
public ExpandableHeightGridView(Context context) {
super(context);
}
public ExpandableHeightGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExpandableHeightGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
/* more code here */
}
If there is no constructor, java must call parent constructor, isn't it ?
Because by default(optional) super()
keyword will call no-arg constructor, So to call argumented constructor of parent class it must to write super()
keyword with arguments
just see how constructor chaining works
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.