Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot override onConfigurationChange in a fragment

I'm trying to overload the funcion to detect an screen orientation change with the following code in a class that inherits from Fragment class.

  override fun onConfigurationChanged(newConfig: Configuration?) {
        newConfig?.let { super.onConfigurationChanged(it) }
        if (newConfig != null) {
            if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {

                Handler().postDelayed({
                    otrosScrollView.fullScroll(ScrollView.FOCUS_UP)
                },600)

            } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {

                Handler().postDelayed({
                    otrosScrollView.fullScroll(ScrollView.FOCUS_UP)
                },600)

            }
        }
    }

But it gives the error that onConfigurationChanged overrides nothing, so not sure how to handle the issue.

What could I do so a fragment reacts to the mentioned event?

like image 210
user2638180 Avatar asked Jan 28 '26 19:01

user2638180


1 Answers

This can happen when you update the sdk for a project and a function definition has changed. In this case, it looks like onConfigurationChanged() no longer accepts a nullable type.

like image 115
Ivan Wooll Avatar answered Jan 31 '26 09:01

Ivan Wooll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!