对象不是抽象的,并且不实现抽象成员吗?

时间:2019-01-05 15:04:57

标签: android kotlin dialog

我已经实现了CustomAlertDialogBuilder,但收到以下警告:

  

该对象不是抽象对象,并且未实现抽象成员

下面是我的代码:

override fun onEditClick(item: Question) {
    CustomAlertDialogBuilder(context).setCancelable(true)

    CustomAlertDialogBuilder(context).addMessage(R.string.chat_message).setPositiveButton(R.string.chat,

        object : CustomAlertDialogBuilder.OnItemDialogClickListener {
            override fun onClick(dialog: CustomAlertDialogBuilder.CustomDialogInterface) {
                val intent = Intent(context, ChatActivity::class.java)
                startActivity(intent)
            }
        }).setNegativeButton("OK", null).build()?.show()
}

下面是错误的屏幕截图:

screenshot of error

CustomDialogBuilder.OnItemDialogClickListener界面下方:

interface OnItemDialogClickListener {
    fun onClick(dialog: CustomDialogInterface)
    fun onClick(arg0: CustomAlertDialogBuilder, arg1: Int)
}

1 个答案:

答案 0 :(得分:0)

您应该添加arg1:Int作为覆盖的onClick函数的第二个参数,并将第一个参数的类型设置为CustomAlertDialogBuilder,例如:

override fun onEditClick(item: Question) {
    CustomAlertDialogBuilder(context).setCancelable(true)

    CustomAlertDialogBuilder(context).addMessage(R.string.chat_message).setPositiveButton(R.string.chat,

    object : CustomAlertDialogBuilder.OnItemDialogClickListener {
        override fun onClick(dialog: CustomAlertDialogBuilder, arg1: Int) {
            val intent = Intent(context, ChatActivity::class.java)
            startActivity(intent)
        }

        override fun onClick(dialog: CustomDialogInterface) {
            // ...
        }
    }).setNegativeButton("OK", null).build()?.show()
}

还要检查是否实现了CustomAlertDialogBuilder.OnItemDialogClickListener的其他方法。