[英]Multiple constructors when extending java class preference using Kotlin
我试图采用这个时间偏好java类并将其转换为Kotlin:
public TimePreference(Context context) {
this(context, null);
}
public TimePreference(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public TimePreference(Context context, AttributeSet attrs,
int defStyleAttr) {
this(context, attrs, defStyleAttr, defStyleAttr);
}
public TimePreference(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
// Do custom stuff here
// ...
// read attributes etc.
}
我能够获得主构造函数,但不能获得辅助构造函数。 我在运行时因布局通胀错误而崩溃。
class SpinnerPreference constructor(context: Context, attrs:
AttributeSet, defStyleAttributes: Int, defStyleRes: Int) :
Preference(context, attrs, defStyleAttributes, defStyleRes) {
}
从commonsware的评论再次检查文档这一次更加一点,这似乎工作:)。
class SpinnerPreference : Preference {
constructor(context: Context, attrs: AttributeSet, defStyleAttributes: Int, defStyleRes: Int) : super(context, attrs, defStyleAttributes, defStyleRes)
constructor(context: Context, attrs: AttributeSet, defStyleAttributes: Int) : super(context, attrs, defStyleAttributes)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context) : super(context)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.