0
votes

I am stuck with this error

Return type of 'onCreateDialog' is not a subtype of the return type of the overridden member 'protected/protected and package/ open fun onCreateDialog(p0: Int): Dialog! defined in androidx.appcompat.app.AppCompatActivity'

I've just migrated my project from java to kotlin and now I am facing this kind of error and it is new to me, so any help will be much appreciated.

Code:

override fun onCreateDialog(id: Int): () -> ProgressDialog? {
        return when (id) {
            progress_bar_type -> ({
                pDialog = ProgressDialog(this)
                pDialog!!.setMessage("Sending Application. Please wait...")
                pDialog!!.isIndeterminate = false
                pDialog!!.max = 100
                pDialog!!.setProgressStyle(ProgressDialog.STYLE_SPINNER)
                pDialog!!.setCancelable(true)
                pDialog!!.show()
                pDialog
            })!!
            else -> null
        }
    }
1
can you post the whole class? can't see why you are overriding onCreateDialog :)Ric17101
It defined as fun onCreateDialog(id: Int): Dialog just remove the method type it agin with suggestion . Also onCreateDialog is deprecated i guess .ADM

1 Answers

1
votes

onCreateDialog is deprecated. The best solution for you would be to make a new class that extends DialogFragment (like MyProgressDialog : DialogFragment)

Then in MyProgressDialog, simply override onCreateDialog

override fun onCreateDialog(savedInstanceState: Bundle): Dialog {
    val dialog = ProgressDialog(getActivity())
    // setup whatever you need
    dialog.setTitle(R.string.title_dialog);

    return dialog;
}

Then you simply create an instance and call show :

MyProgressDialog().show(supportFragmentManager, "SomeTag")