java - 使用 Kotlin 扩展 java 类首选项时的多个构造函数
问题描述
我正在尝试采用这个 Time Preference 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)
}
推荐阅读
- java - 如何在 PL/SQL 中的 Map 中返回结果?
- python - 输出 ==> elif mid_number
cards= [20,19,18,17,16,15,13, 11, 10, 7, 4, 3, 1, 0], query=1 def checker(cards,query
- sas - 在 Sas Miner 中修改变量
- c++ - 如何在另一个 Qt 线程上运行它?
- reactjs - Ref 动态反应
- python - 删除 NaN 和列值更改之间的行
- syntax-error - 在 OCaml 中编写函数的问题
- javascript - 播放视频时重新加载 Youtube 页面?
- python - 如何从 Django 运行多个 selenium 脚本?
- python - 在网站上的回复中给出了难以理解的象形文字