简体   繁体   中英

android 4 onCreateDialog return type incompatible when overriding

The code below won't compile. I understand that when doing an override, the replacement class must match the signature of the original class exactly, but I think I'm following the example from the Android documentation carefully.

error messages:

overrides android.app.Activity.onCreateDialog
The return type is incompatible with Activity.onCreateDialog(int)

onCreateDialog() method:

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 0:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.drawable.ic_launcher)
            .setTitle("This is a dialog with a stupid message...")

            //more code here setting additional properties
            );
    return builder.create();
    }
}

You need a default return block in your switch or a return after the switch. You can return null in those cases.

The onCreateDialog() method requires a Bundle as the argument, not an int. You should pass in a Bundle that contains the int id and retrieve that value from the Bundle for use in the switch statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM