# Android : Kotlin : Composable Button

**URL:** <https://discuss.kotlinlang.org/t/android-kotlin-composable-button/29885>\
**Category:** Android\
**Created:** [February 12, 2025, 6:01pm UTC](https://discuss.kotlinlang.org/t/android-kotlin-composable-button/29885 "2025-02-12T18:01:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![afo.conseil24](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/afo.conseil24/32/11088_2.png) [@afo.conseil24](https://discuss.kotlinlang.org/u/afo.conseil24)\
**Post date:** [February 12, 2025, 6:01pm UTC](https://discuss.kotlinlang.org/t/android-kotlin-composable-button/29885/1 "2025-02-12T18:01:18Z")

</div>

Bonjour tout le monde,  
D’avance excusez moi si je ne suis pas au bon endroit. C’est ma première fois.

J’apprend tout seul a développer sur Android Studio sur Kotlin

Je souhaite faire une application (débutant) qui me permette de faire plus 1 et appeler une fonction.

Code : [Sélectionner tout](https://www.developpez.net/forums/d2174481/java/edi-outils-java/environnement-developpement-integre-edi/android-studio/android-kotlin-composable-button/#) - [Visualiser dans une fenêtre à part](https://www.developpez.net/forums/d2174481/java/edi-outils-java/environnement-developpement-integre-edi/android-studio/android-kotlin-composable-button/#)  
@Composable fun afficheContenu(etape: setStepAppVal, img: Painter, name: String, rmk: String, modifier: Modifier){ Column( modifier = Modifier .fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { Button( onClick = { nextStepApp(etape, modifier) } ) { Image( painter = img, contentDescription = name, modifier = Modifier .size(200.dp) ) } Spacer(modifier = Modifier.height(16.dp)) Text( text = rmk ) } } @Composable fun nextStepApp(etape: setStepAppVal, modifier: Modifier){ etape.modifierVal(etape.value+1) stepApp(etape, modifier) }

Quand

Code : [Sélectionner tout](https://www.developpez.net/forums/d2174481/java/edi-outils-java/environnement-developpement-integre-edi/android-studio/android-kotlin-composable-button/#) - [Visualiser dans une fenêtre à part](https://www.developpez.net/forums/d2174481/java/edi-outils-java/environnement-developpement-integre-edi/android-studio/android-kotlin-composable-button/#)

onClick = { nextStepApp(etape, modifier) }

il ne veut pas que j’appelle une function @Composable, mais si j’enlève @Composable à la function “fun nextStepApp”, il me dit de le mettre ?  
Du coup le serpent se mort la queue !

Depuis le onClick() j’ai besoin de changer une valeur puis d’appeler une function.  
Comment faire ?

Merci de votre aide.  
Bonne journée

---

<div class="post-metadata">

**Author:** ![afo.conseil24](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/afo.conseil24/32/11088_2.png) [@afo.conseil24](https://discuss.kotlinlang.org/u/afo.conseil24)\
**Post date:** [February 13, 2025, 10:54am UTC](https://discuss.kotlinlang.org/t/android-kotlin-composable-button/29885/3 "2025-02-13T10:54:08Z")

</div>

Hello everyone,  
Apologies in advance if I’m not in the right place. It’s my first time.

I’m teaching myself to develop on Android Studio on Kotlin

I want to make an application (beginner) that allows me to do plus 1 and call a function.  
When

Code: Select all - View in a separate window

onClick = { nextStepApp(step, modify) }

it doesn’t want me to call a @Composable function, but if I remove @Composable from the “fun nextStepApp” function, it tells me to put it ?  
Suddenly the snake died its tail!

From onClick() I need to change a value then call a function.  
How to do it?

Thank you for your help.  
Good day

---

<div class="post-metadata">

**Author:** ![Landei](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/landei/32/9407_2.png) [@Landei](https://discuss.kotlinlang.org/u/Landei)\
**Post date:** [February 13, 2025, 9:20pm UTC](https://discuss.kotlinlang.org/t/android-kotlin-composable-button/29885/4 "2025-02-13T21:20:53Z")

</div>

As there is no other answer, I will give it a shot, even though I’m learning Android and Compose myself. I can’t really say something about the behavior you see, but I think it won’t work the way you try. Composable functions have to be stateless, as they can be interrupted at any point for all kinds of reasons (like turning the phone), or even disposed.

You need a “safe place” outside of the Composable function tree to put your data, and you have to make sure that the application is aware of the changes and doesn’t lose it. The safe place can be your activity, in more advanced applications you often see viewmodels. There are several ways to make sure that data are really stored, e.g. the `remember` function. And to make sure that the application is notified about changes and updates the UI accordingly, there are also a lot of ways, the most basic being to wrap it in a `MutableState` (but there are also flows etc).

Here is the easiest example I could find for a Android Compose app that changes a value and displays the results:

[![](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/b/be50b55bffb634b56ac19439206916185f7e59c9.jpeg "Button Click Counter In Android Studio Jetpack Compose | Count Button Click In Jetpack Compose") ](https://www.youtube.com/watch?v=8YKlgkO5yE0)

Note that the value needed for the UI (here `count`) is passed as a normal argument to the Composable function, but is not directly modified. This is done by getting also a lambda argument passed for onClick, which was prepared in the `MainActivity`, where you have access to these data. I think you can do the same with your `nextStepApp` call.
