Search code examples
androidkotlinclick

Compose method called once


I try to call very simple compose method from fragment button but when i try to click on the button the compose method just called once and the log shown once !

@Composable
fun showOverlay(){
    Log.e("showverlayTag", "showVodafoneOverlay: ", )
} 

And the click is here inside the onCreate fragment :

binding.sCashMoneyTransferGiftsSwitch.setOnClickListener {
        binding.composeView.setContent {
            showOverlay()
        }

    }

i want whatever i click on the button the log is called and shown on the logcat.


Solution

  • I found the solution.

    Compose view called once when you click the button because nothing happened after click the button that trigger the recomposition and re call the method .. to do that without handle state or any thing just call compose.setContent={} .. this code act as reset the compose and then every click will treat compose as first time clicking.