https://kotlinlang.org logo
#compose
Title
# compose
a

Aaron Waller

06/09/2022, 3:52 PM
How to call functions inside AndroidView or AndroidViewBinding composable? In the old view system if I needed to update multiple views in multiple places, I simply created a function for that:
Copy code
private fun updateViews(value1: Int, value2: Int) = with(binding) {
    timelineTextView.text = "$value1, $value2"
    ... A lot of other stuff

}
How is that possible when using the AndroidViewBinding Composable?
Copy code
@Composable
fun MainScreen(){
    AndroidViewBinding(ActivityPlayBinding::inflate) {
        playButton.setOnClickListener {
            updateViews(value1, value2)
        }

        playButton2.setOnClickListener {
            updateViews(value1, value2)
        }
    }
}
How can I call that
updateViews
function in Compose? Simply putting the content of updateViews function where the function gets called feels really bad cause that causes a lot of duplicate code. But I cant seem to find the right way to do it…
m

mkrussel

06/09/2022, 3:58 PM
You don't update views in compose. Instead you should update your state and compose will recompose the views that use that state.
🤝 1
3 Views