{"id":83819,"date":"2021-08-25T09:00:38","date_gmt":"2021-08-25T03:30:38","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=83819"},"modified":"2024-08-05T11:19:13","modified_gmt":"2024-08-05T05:49:13","slug":"android-radiogroup-radiobutton-and-checkbox","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/","title":{"rendered":"Android RadioGroup, RadioButton and Checkbox"},"content":{"rendered":"<p>In this article, we will dive into some essential UI elements that can significantly enhance user interaction: Android RadioButton, RadioGroup, and Checkboxes. These components are the building blocks of creating intuitive and interactive forms, surveys, and preference settings in your apps. Unlock the potential of these versatile UI elements and see how they can make your Android applications more dynamic and user-friendly. So let&#8217;s dive in!<\/p>\n<h3>What is a RadioButton in Android?<\/h3>\n<p>Android RadioButton has only two states: checked or unchecked. Apart from these, the radio button can\u2019t have any other value. You can\u2019t uncheck a checked RadioButton. The only way to uncheck is to select some other RadioButton belonging to that RadioGroup. Usually, RadioButtons are used to take mandatory inputs where the user has to choose something and can\u2019t leave that field unchecked.<\/p>\n<p>A very general example is while selecting your gender. You can\u2019t leave the field empty; you need to choose either Male, female or prefer not to say.<\/p>\n<p>Using the below code, you can create a RadioButton in Android.<\/p>\n<p><strong>XML Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;RadioButton android:id=\"@+id\/your_radio_button\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Samsung\"\r\n                android:onClick=\"onRadioButtonClicked\"\r\n\/&gt;<\/pre>\n<h4>Attributes of RadioButton in Android<\/h4>\n<table>\n<tbody>\n<tr>\n<td><b>Attribute Name<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: id<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cid\u201d attribute is used to identify your radio buttons uniquely.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: checked<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cchecked\u201d property of radio buttons is by default false. If you keep it as true then the radio button is checked when your activity loads without you even clicking on it.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: gravity<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cgravity\u201d attribute is used to specify the alignment of the radio buttons.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: text<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201ctext\u201d attribute is used to specify the text that should appear beside the RadioButton.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: textSize<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201ctextSize\u201d attribute is used to specify the size of the text element that comes with your RadioButton.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: textColor<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201ctextColor\u201d attribute is used to specify the color of the text that appears beside the RadioButton.<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: padding<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cpadding\u201d attribute is used to specify the gapping between the element boundaries and the content of the RadioButton.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: background<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cbackground\u201d attribute is used to specify the color or image that should be present at the back of your RadioButton.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: onClick<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201conClick\u201d attribute is used to register a click event listener with your RadioButton.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: textStyle<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201ctextStyle\u201d attribute is used to specify the style of your text present in the RadioButton. (italic, bold or regular<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: visibility<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cvisibility\u201d attribute is used to hide or show your RadioButton.\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>What is a RadioGroup in Android?<\/h3>\n<p>RadioGroup is a collection of various RadioButtons seeking responses for the same field. For example, if Male, Female, and Others are Radio Buttons, then Gender is the RadioGroup containing these values. The point to note is you can select only one RadioButton from a given set of RadioButtons in the RadioGroup.<\/p>\n<p>The RadioGroup can have multiple RadioButtons depending on the scenario, but the user can select only from them at the end.<\/p>\n<p>Using the below code, you can create a radio group in Android.<\/p>\n<p><strong>XML Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;RadioGroup\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:padding=\"10dp\"\r\n            android:orientation=\"vertical\"&gt;\r\n\r\n            &lt;RadioButton android:id=\"@+id\/your_radio_button\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Samsung\"\r\n                android:onClick=\"onRadioButtonClicked\"\/&gt;\r\n           \r\n        &lt;\/RadioGroup&gt;<\/pre>\n<h3>What is a CheckBox in Android?<\/h3>\n<p>CheckBox has two states similar to RadioButton, i.e., checked or unchecked. The point to note is in CheckBox, and you can uncheck the box by yourself. Here if you select the other checkbox, then your current checkbox won\u2019t be chosen. The user doesn\u2019t have any restrictions while selecting checkboxes. They can even select all the checkboxes provided if they want.<\/p>\n<p>Using the below code, you can create your checkbox in Android.<\/p>\n<p><strong>XML Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;CheckBox android:id=\"@+id\/your_check_box\"\r\n               android:layout_width=\"wrap_content\"\r\n               android:layout_height=\"wrap_content\"\r\n               android:text=\"Java\"\r\n               android:onClick=\"onCheckboxClicked\"\/&gt;\r\n<\/pre>\n<h4>Attributes of Android CheckBox<\/h4>\n<table>\n<tbody>\n<tr>\n<td><b>Attribute Name<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: id<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cid\u201d attribute is used to identify your checkboxes uniquely.<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: checked<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Checkboxes&#8217; &#8220;checked&#8221; attribute is set to false by default. If you keep it as true, then the check box is automatically checked when your activity loads without you even clicking on it.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: gravity<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cgravity\u201d attribute is used to specify the alignment of your checkboxes.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: text<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201ctext\u201d attribute is used to specify the text that should appear beside the CheckBox.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: textSize<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201ctextSize\u201d attribute is used to specify the size of the text that comes along with your CheckBox.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: textColor<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201ctextColor\u201d attribute is used to specify the color of the text that appears beside the CheckBox.<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: padding<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cpadding\u201d attribute is used to specify the gapping between the element boundaries and the content of the CheckBox.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: background<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cbackground\u201d attribute is used to specify the color or image that should be present at the back of your CheckBox.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: onClick<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201conClick\u201d attribute is used to register a click event listener with your CheckBox.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: textStyle<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201ctextStyle\u201d attribute is used to specify the style of your text present in the CheckBox. (italic, bold or regular)<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">android: visibility<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The \u201cvisibility\u201d attribute is used to hide or show your CheckBox.\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Implementation of Android RadioButton, RadioGroup, and CheckBoxes<\/h3>\n<p>We will try to make a quiz screen to see Multiple Choice Questions for the implementation. The MCQ will be of two types one will be single correct, and the other would be multiple correct. For the single option correct question, we will use RadioGroup and RadioButtons, while for the multi-option correct question, we will use the CheckBox.<\/p>\n<p>So, follow the elbow steps to develop your quiz screen.<\/p>\n<p><strong>1:<\/strong> You need first to start your Android Studio and click on Create a new Project.<\/p>\n<p><strong>2:<\/strong> Now select an empty activity and then provide your project name and select API level22 and then click on Finish<\/p>\n<p><strong>3:<\/strong> Now open the actyivity_main.xml file of your project and paste the below code.<\/p>\n<p><strong>Code:activity_main.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n\r\n&lt;ScrollView\r\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n\r\n    &lt;LinearLayout\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"\r\n        android:orientation=\"vertical\"\r\n        tools:context=\".MainActivity\"&gt;\r\n\r\n        &lt;TextView\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:text=\"TechVidvan Quiz Screen\"\r\n            android:textSize=\"30sp\"\r\n            android:textStyle=\"bold\"\r\n            android:textColor=\"#3F51B5\"\r\n            android:gravity=\"center\"\r\n            android:layout_marginTop=\"20dp\"\r\n            android:layout_marginBottom=\"20dp\"\r\n            android:id=\"@+id\/title\"\/&gt;\r\n\r\n        &lt;TextView\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:text=\"Which of the following company manufactures Iphone devices?\"\r\n            android:paddingLeft=\"20dp\"\r\n            android:paddingRight=\"20dp\"\r\n            android:textSize=\"18sp\"\r\n            android:layout_marginTop=\"10dp\"\r\n            android:textColor=\"@color\/black\"\r\n            \/&gt;\r\n\r\n        &lt;RadioGroup\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:padding=\"10dp\"\r\n            android:orientation=\"vertical\"&gt;\r\n\r\n            &lt;RadioButton android:id=\"@+id\/samsung\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Samsung\"\r\n                android:onClick=\"onRadioButtonClicked\"\/&gt;\r\n            &lt;RadioButton android:id=\"@+id\/nokia\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Nokia\"\r\n                android:onClick=\"onRadioButtonClicked\"\/&gt;\r\n            &lt;RadioButton android:id=\"@+id\/apple\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Apple\"\r\n                android:onClick=\"onRadioButtonClicked\"\/&gt;\r\n            &lt;RadioButton android:id=\"@+id\/vivo\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Vivo\"\r\n                android:onClick=\"onRadioButtonClicked\"\/&gt;\r\n        &lt;\/RadioGroup&gt;\r\n\r\n        &lt;TextView\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:text=\"Select Programming Languages from below\"\r\n            android:paddingLeft=\"20dp\"\r\n            android:paddingRight=\"20dp\"\r\n            android:textSize=\"18sp\"\r\n            android:layout_marginTop=\"10dp\"\r\n            android:textColor=\"@color\/black\"\r\n            \/&gt;\r\n\r\n        &lt;LinearLayout\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:orientation=\"vertical\"\r\n            android:padding=\"10dp\"&gt;\r\n\r\n            &lt;CheckBox android:id=\"@+id\/python\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Python\"\r\n\r\n                android:onClick=\"onCheckboxClicked\"\/&gt;\r\n            &lt;CheckBox android:id=\"@+id\/java\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Java\"\r\n                android:onClick=\"onCheckboxClicked\"\/&gt;\r\n\r\n            &lt;CheckBox android:id=\"@+id\/kotlin\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Kotlin\"\r\n                android:onClick=\"onCheckboxClicked\"\/&gt;\r\n\r\n            &lt;CheckBox android:id=\"@+id\/Windows\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Windows\"\r\n                android:onClick=\"onCheckboxClicked\"\/&gt;\r\n\r\n            &lt;CheckBox android:id=\"@+id\/Ubuntu\"\r\n                android:layout_width=\"wrap_content\"\r\n                android:layout_height=\"wrap_content\"\r\n                android:text=\"Ubuntu\"\r\n                android:onClick=\"onCheckboxClicked\"\/&gt;\r\n\r\n        &lt;\/LinearLayout&gt;\r\n\r\n        &lt;Button\r\n            android:layout_width=\"wrap_content\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:layout_gravity=\"center\"\r\n            android:text=\"Submit\"\r\n            android:onClick=\"checkResponses\"\r\n            \/&gt;\r\n\r\n\r\n    &lt;\/LinearLayout&gt;\r\n\r\n&lt;\/ScrollView&gt;\r\n<\/pre>\n<p><strong>4:<\/strong> After you are done with your layout designing, you need to open your MainActivity.kt file and paste the below code.<\/p>\n<p><strong>Code: MainActivity.kt<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.techvidvan.techvidvanradiocheck\r\n\r\nimport androidx.appcompat.app.AppCompatActivity\r\nimport android.os.Bundle\r\nimport android.view.View\r\nimport android.widget.CheckBox\r\nimport android.widget.RadioButton\r\nimport android.widget.Toast\r\n\r\nclass MainActivity : AppCompatActivity()\r\n{\r\n    \/\/declaring variables\r\n\r\n    var python = false\r\n    var java = false\r\n    var kotlin = false\r\n    var apple = false\r\n\r\n    override fun onCreate(savedInstanceState: Bundle?)\r\n    {\r\n        super.onCreate(savedInstanceState)\r\n        setContentView(R.layout.activity_main)\r\n    }\r\n\r\n    fun checkResponses(view: View) {\r\n\r\n        \/\/checking if your responses are correct or not\r\n        if(apple &amp;&amp; python &amp;&amp; java &amp;&amp; kotlin)\r\n        {\r\n            Toast.makeText(this@MainActivity, \"Your responses are correct\", Toast.LENGTH_LONG).show()\r\n        }\r\n        else\r\n        {\r\n            Toast.makeText(this@MainActivity, \"Your responses are incorrect. Please try again :(\", Toast.LENGTH_LONG).show()\r\n        }\r\n    }\r\n\r\n    fun onCheckboxClicked(view: View)\r\n    {\r\n        \/\/checking if checkbox is clicked\r\n        if (view is CheckBox) {\r\n            val checked: Boolean = view.isChecked\r\n\r\n            \/\/check which Checkbox was pressed\r\n            when (view.id)\r\n            {\r\n                \/\/if python or java or kotlin are selected then\r\n                \/\/keep their values\r\n                \/\/in their variables\r\n                R.id.python -&gt; {\r\n                    python = checked\r\n                }\r\n                R.id.java -&gt; {\r\n                    java = checked\r\n                }\r\n                R.id.kotlin -&gt; {\r\n                    kotlin = checked\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    fun onRadioButtonClicked(view: View)\r\n    {\r\n        if (view is RadioButton) {\r\n\r\n            val checked = view.isChecked\r\n\r\n            \/\/ Check which radio button was pressed\r\n            when (view.id)\r\n            {\r\n                \/\/if you selected apple then change its value\r\n                R.id.apple -&gt;\r\n                  apple = checked\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>Now run your application, and then you will find a screen like below.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/App_Output_1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-84318\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/App_Output_1.jpg\" alt=\"Android RadioButton Example\" width=\"1080\" height=\"2280\" \/><\/a><\/p>\n<p>After you select your desired responses in the application, then the screen will appear as follows.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/App_Output_2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-84319\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/App_Output_2.jpg\" alt=\"Android RadioGroup Example\" width=\"1080\" height=\"2280\" \/><\/a><\/p>\n<p>Now click on Submit. You can notice that your responses are wrong, and you got a Toast stating the same.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/App_Output_3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-84320\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/App_Output_3.jpg\" alt=\"Android RadioButton\" width=\"1080\" height=\"2280\" \/><\/a><\/p>\n<p>Let\u2019s see by putting the correct responses, and you will receive a Toast stating that your answers are correct.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/App_Output_4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-84321\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/App_Output_4.jpg\" alt=\"Android Checkbox and Radiobutton\" width=\"1080\" height=\"2280\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>So, through this article, you came across Android RadioButton, RadioGroup, and Checkbox. You got to know what each of them means and how you can add them to Android. Moving further, you saw the attributes of RadioButton and CheckBoxes. Finally, you came across the implementation of the three of them by developing a quiz screen.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will dive into some essential UI elements that can significantly enhance user interaction: Android RadioButton, RadioGroup, and Checkboxes. These components are the building blocks of creating intuitive and interactive forms,&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":84316,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2791],"tags":[4091,4092,4093],"class_list":["post-83819","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","tag-android-checkboxes","tag-android-radiobuttons","tag-android-radiogroups"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android RadioGroup, RadioButton and Checkbox - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn about Android RadioButtons, RadioGroups, and Checkboxes with their attributes and implementations. Learn to add them in Android.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android RadioGroup, RadioButton and Checkbox - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn about Android RadioButtons, RadioGroups, and Checkboxes with their attributes and implementations. Learn to add them in Android.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-25T03:30:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-05T05:49:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-RadioButton-RadioGroup-and-CheckBox.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android RadioGroup, RadioButton and Checkbox - TechVidvan","description":"Learn about Android RadioButtons, RadioGroups, and Checkboxes with their attributes and implementations. Learn to add them in Android.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/","og_locale":"en_US","og_type":"article","og_title":"Android RadioGroup, RadioButton and Checkbox - TechVidvan","og_description":"Learn about Android RadioButtons, RadioGroups, and Checkboxes with their attributes and implementations. Learn to add them in Android.","og_url":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-08-25T03:30:38+00:00","article_modified_time":"2024-08-05T05:49:13+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-RadioButton-RadioGroup-and-CheckBox.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Android RadioGroup, RadioButton and Checkbox","datePublished":"2021-08-25T03:30:38+00:00","dateModified":"2024-08-05T05:49:13+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/"},"wordCount":1075,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-RadioButton-RadioGroup-and-CheckBox.jpg","keywords":["Android checkboxes","Android RadioButtons","Android RadioGroups"],"articleSection":["Android Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/","url":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/","name":"Android RadioGroup, RadioButton and Checkbox - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-RadioButton-RadioGroup-and-CheckBox.jpg","datePublished":"2021-08-25T03:30:38+00:00","dateModified":"2024-08-05T05:49:13+00:00","description":"Learn about Android RadioButtons, RadioGroups, and Checkboxes with their attributes and implementations. Learn to add them in Android.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-RadioButton-RadioGroup-and-CheckBox.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-RadioButton-RadioGroup-and-CheckBox.jpg","width":1200,"height":628,"caption":"Android RadioButton, RadioGroup, and CheckBox"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/android-radiogroup-radiobutton-and-checkbox\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Android RadioGroup, RadioButton and Checkbox"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=83819"}],"version-history":[{"count":2,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83819\/revisions"}],"predecessor-version":[{"id":447597,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83819\/revisions\/447597"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/84316"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=83819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=83819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=83819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}