androidandroid-jetpack-composecomposable

@Composable in a overridden method?


I would like to draw a @Composable on a override method, like

@Composable
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
    Greeting()
}

Unfortunately, I can not mark a override onKeyDown() with @Composable, since I get:

Conflicting overloads: @Composable public open fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean defined in com.example.emptycompose.MainActivity, public open fun onKeyDown(p0: Int, p1: KeyEvent!): Boolean defined in androidx.appcompat.app.AppCompatActivity

How can I use a @Composable in e.g. a override onKeyDown()?


Solution

  • This happen when you rename your .kt file.

    For example, I rename KKbutton.kt to KKButton.kt and this error happen.

    Clean and rebuild fix this.