'Set Content Compose Dialog Works on Phone, but Not Tablet? - Android

I've run this through the debugger a hundred times and stepped into the setContent over and over. I can't figure out why. No errors given.

Works perfectly on Android phone.

When on a tablet, the entire setContent code block is skipped over.

This is the piece of the fragment that deals with opening the dialog. Any ideas?

    (activity as? MapActivity)?.findViewById<ComposeView>(R.id.map_fragment_container_composeview)
        ?.setContent {
            // Delegate to observe the showDialog state in viewModel
            val showDialogState: Boolean by dialog.showDialog.collectAsState()

            MdcTheme {
                OptionSelectComposeDialog(
                    show = showDialogState,
                    onDismiss = dialog::onDialogDismiss,
                    onConfirm = dialog::onDialogConfirm,
                    vm = dialog,
                )
            }
        }


Solution 1:[1]

Copying from comments to show the resolution (thanks to @ianhanniballake and @MARSK)

Just to further document for anyone else who comes across, we use a layout folder with the default (phone) layout. There was a separate folder layout-sw600dp that is used for tablets. I got this confused because the files in both folders have the same names, but the composeview needed to be added to both layouts.

Once the composeview was added to the layout-sw600dp folder, the issue went away. I also removed many of the nullable (?) markers. Those markers were preventing any errors from appearing.

Update: Added the nullable ? markers back in. I'm told it's a good way to future-proof your code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1