代码A效果很好,但是当我用import android.support.v7.preference.DialogPreference
onCreateDialogView() override nothing
onDialogClosed() override nothing
showDialog() override nothing
时出错
为什么?
错误
import android.preference.DialogPreference
import android.app.AlertDialog
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import android.view.View
import info.dodata.mirror.R
import android.widget.EditText
import org.jetbrains.anko.*
import utility.PreferenceTool
class DialogChangePassword(context: Context, attrs: AttributeSet) : DialogPreference(context, attrs) {
private lateinit var mView: View
private lateinit var mContext: Context
init {
dialogLayoutResource = R.layout.item_custom_password_dialog
}
override fun onCreateDialogView(): View {
mView = super.onCreateDialogView()
mContext=mView.context
return mView
}
override fun onDialogClosed(positiveResult: Boolean) {
super.onDialogClosed(positiveResult)
}
override fun showDialog(state: Bundle?) {
super.showDialog(state)
val d = dialog as AlertDialog
d.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
d.dismiss()
}
}
}
代码A
{{1}}
答案 0 :(得分:2)
请参阅文档。
onCreateDialogView() override nothing
onDialogClosed() override nothing
showDialog() override nothing
这些方法在android.preference.DialogPreference
(#https://developer.android.com/reference/android/preference/DialogPreference)中受到保护/打开,但没有android.support.v7.preference.DialogPreference
(#https://developer.android.com/reference/android/support/v7/preference/DialogPreference)中的方法。
这些类不一样,它们没有相同的公共接口。这就是原因。