Object is not abstract and does not implement abst

2019-03-06 16:49发布

问题:

I have implemented CustomAlertDialogBuilder but I am getting the following warning:

The object is not abstract and does not implement abstract member

Below is my code:

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()
}

Below is the screenshot of the error:

screenshot of error

Below CustomDialogBuilder.OnItemDialogClickListener interface:

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

回答1:

You should add arg1:Int as the second param of overridden onClick function and make type of first parameter as CustomAlertDialogBuilder, e.g.:

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()
}

Also check if other methods of CustomAlertDialogBuilder.OnItemDialogClickListener are implemented.