Best Tutorial for AndroidDevelopers

Android App Development

Stay ahead with the latest tools, trends, and best practices in Android development

Radio Buttons in Jetpack Compose

Radio Buttons in Jetpack Compose - Responsive Blogger Template
Radio Buttons in Jetpack Compose

What is Radio Button?

Radio Buttons are just like buttons but it is used in different way. If we need a group of buttons allow us to select one of them, In that case Radio Button may be used.
Suppose that we are creating MCQ questions with four corresponding options for that questions in that case Radio Buttons are very useful material design components.
As In Radio Button we can only select one option so if you need to choose more than one option use Checkbox that let the users to select multiple options.

Radio buttons are used in many Mobile Applications for selecting only one option from the list of two or more options. So, We can also use it allow users to select any one action in a list of actions.

If we think that the we need to see all available options side-by-side but If it's not necessary to show all options side-by-side, we can use a spinner in place of Radio Buttons.

Common Real-World Use Cases

  • Payment method selection
  • Language preferences
  • Gender selection
  • Subscription plans
  • Quiz and exam apps
  • Settings screens

Best Practices for RadioButton in Jetpack Compose (2026)

  • Always place text next to the RadioButton
  • Make the entire row clickable
  • Use Modifier.selectableGroup() for accessibility
  • Avoid too many RadioButtons in long lists
  • Use meaningful option names
In this tutorial, we will learn to create radio buttons.

How to create a new project in Android Studio images  radio button tutorial




Steps :

Create a New Project and select Empty Activity In my case, application name is Coding Bihar you can use any other name.

MainActivity

package com.example.codingbihar
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.example.codingbihar.ui.theme.CodingBiharTheme

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            CodingBiharTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    RadioButton()
                   }
            }
        }
    }
}



Create a new Kotlin file for Radio Button and named it as RadioButton

How to create a new file in Android Studio images

RadioButton

package com.example.codingbihar

import android.widget.Toast
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp

@Composable
fun RadioButton() {
    val radioOptions = listOf("RadioButton 1", "RadioButton 2", "RadioButton 3","RadioButton 4")
    // mutableStateOf("") → Not any RadioButton is selected by default
    val (selectedOption, onOptionSelected) = remember { mutableStateOf("") }
    
    Column(Modifier.selectableGroup()) {
        radioOptions.forEach { text ->
            Row(
                Modifier
                    .fillMaxWidth()
                    .height(56.dp)
                    .selectable(
                        selected =true,
                       // selected = (text == selectedOption),
                        onClick = { onOptionSelected(text) },
                        role = Role.RadioButton
                    )
                    .padding(horizontal = 16.dp),
                verticalAlignment = Alignment.CenterVertically
            ) {
                val context = LocalContext.current.applicationContext
                RadioButton(
                    selected = (text == selectedOption),
                    onClick = {
                        onOptionSelected(text)
                        Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
                    }
                )
                Text(
                    text = text,
                    style = MaterialTheme.typography.bodyLarge,
                    modifier = Modifier.padding(start = 16.dp)
                )
            }
        }
    }
}

OUTPUT :

Radio Buttons in Jetpack Compose Screenshot 1
Radio Buttons in Jetpack Compose Screenshot 2

Frequently Asked Questions (FAQ)

1. What is a Radio Button in Android?

A Radio Button is a UI component that allows users to select only one option from a group of available choices. It is commonly used in forms, surveys, quizzes, and settings screens.

2. Why are Radio Buttons used?

Radio Buttons are used when users must choose a single option from multiple choices. They help prevent multiple selections and make decision-making easier.

3. What is the difference between a Radio Button and a Checkbox?

A Radio Button allows only one selection within a group, while a Checkbox allows users to select multiple options at the same time.

4. When should I use Radio Buttons?

Use Radio Buttons when:

There are two or more options.
Users need to select only one option.
All options should be visible on the screen.

Examples:

Gender selection
Payment method selection
Quiz answers
Theme selection

5. What is a Radio Group?]

A Radio Group is a container that holds multiple Radio Buttons and ensures that only one Radio Button can be selected at a time.

6. Can multiple Radio Buttons be selected simultaneously?

No. When Radio Buttons are placed inside the same Radio Group, only one option can be selected.

7. What happens when a user selects another Radio Button?

The previously selected Radio Button is automatically deselected, and the new one becomes selected.

8. Are Radio Buttons part of Material Design?

Yes. Material Design provides Radio Buttons as a standard component for single-choice selection in Android applications.

9. When should I use a Spinner instead of Radio Buttons?

Use a Spinner when:

There are many options.
Screen space is limited.
It is not necessary to display all options at once.

Use Radio Buttons when users should see all available choices immediately.

10. Can Radio Buttons have a default selected option?

Yes. Developers can set one Radio Button as selected by default to provide an initial choice for users.

11. Are Radio Buttons accessible?

Yes. Properly labeled Radio Buttons improve accessibility and help screen readers identify available choices for users.

12. What are common use cases of Radio Buttons?

Common use cases include:

Multiple Choice Questions (MCQs)
Language selection
Subscription plans
Payment methods
Delivery options
Theme preferences

13. Can Radio Buttons be customized?

Yes. Developers can customize their colors, size, appearance, and behavior to match the application's design.

14. What is the main advantage of Radio Buttons?

The main advantage is that they provide a clear and simple way for users to select exactly one option from a list of choices.

15. What is the main limitation of Radio Buttons?

Radio Buttons are not suitable when users need to select multiple options. In such cases, Checkboxes should be used instead.

Conclusion

Radio Buttons are an essential UI component for single-choice selection. They provide a simple, intuitive, and user-friendly way to choose one option from multiple choices, making them ideal for forms, settings, surveys, and MCQ-based applications.


Sandeep Kumar - Android Developer

About the Author

Sandeep Kumar is an Android developer and educator who writes beginner-friendly Jetpack Compose tutorials on CodingBihar.com. His focus is on clean UI, Material Design 3, and real-world Android apps.

SkillDedication

— Python High Level Programming Language- Expert-Written Tutorials, Projects, and Tools—

Coding Bihar

Welcome To Coding Bihar👨‍🏫