‫Welcome back.
‫In this video, we'll learn about radio buttons in Android studio.
‫A radio button is a widget that allows users to select a single option from a set of mutually exclusive
‫choices.
‫It's commonly used in scenarios where users need to choose one option from multiple options presented
‫in a list.
‫Let's take an example.
‫In Android studio.
‫Let's start defining a radio group at first, and then we need to define a radio button Radio group.
‫The radio group ensures that only one radio button can be selected at a time.
‫So inside this radio group, I can place many radio buttons.
‫I'll create two radio buttons.
‫So these two radio buttons are placed inside a radio group that allows us to select only one radio button
‫at a time.
‫I need to add the constraints here to the radio group.
‫Now let's create a reference to this radio group that allows the user to select only one single option
‫at a time from these radio buttons.
‫I'll start with Radio Group to listen for changes in the selected option that the user select.
‫We need to use uncheck the change listener.
‫So I'll use radio group dot set on checked change listener new and the uncheck the change method is
‫override.
‫So this method is called When the selected option changes, the ID of the selected radio button is passed
‫as checked ID, which you can use to determine which option was selected.
‫So for that I'll create a reference for Radio buttons radio button equal to find the view by ID.
‫This is not the case that I need to pass our id dot the radio button one or radio button two.
‫No, because check id id will do this job, so I need to pass checked id again.
‫The id of the selected radio button is passed.
‫When as checked id parameter.
‫Then I need to display a toast message telling us the option that we select.
‫You select and I'll use radio button dot get text dot toString.
‫Let's run the application and this is our application.
‫If I select Tomato, you select tomato toast message will appear cheese.
‫And this is for the cheese.
‫You can see that only one single option is allowed at a time.
‫So radio button widgets are particularly useful when users need to make a single choice from a list
‫of options.
‫They are often used in forms, quizzes, surveys and other scenarios involving exclusive choices.