{"id":12105,"date":"2014-07-23T16:12:31","date_gmt":"2014-07-23T13:12:31","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=12105"},"modified":"2019-04-24T16:06:23","modified_gmt":"2019-04-24T13:06:23","slug":"android-radiogroup-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/","title":{"rendered":"Android RadioGroup Example"},"content":{"rendered":"<p><a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/RadioGroup.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>RadioGroup<\/code><\/a> is a widget in Android which groups <code>RadioButtons<\/code>. More specifically,  the use of <code>RadioGroup<\/code> provides the capability of selecting only one <code>RadioButton<\/code> from the set. When the user chooses one <code>RadioButton<\/code>, the previous one that was selected, becomes automatically unchecked.<\/p>\n<p>In our example we are going to show you the use of <code>RadioGroup<\/code> in the Android apps.<\/p>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<p>For this tutorial, we will use the following tools in a Windows 64-bit platform:<\/p>\n<ol>\n<li>JDK 1.7<\/li>\n<li>Eclipse 4.2 Juno<\/li>\n<li>Android SDK 4.1<\/li>\n<\/ol>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip project creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<h2>1. Create a New Android Application Project<\/h2>\n<p>Open Eclipse IDE and go to File \u2192 New \u2192 Project \u2192 Android Application Project.<\/p>\n<p>Specify the name of the application, the project and the package and then click Next.<\/p>\n<p><figure id=\"attachment_12107\" aria-describedby=\"caption-attachment-12107\" style=\"width: 498px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_proj1.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_proj1.png\" alt=\"Figure 1. Create a new Android application\" width=\"498\" height=\"457\" class=\"size-full wp-image-12107\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_proj1.png 498w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_proj1-300x275.png 300w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><\/a><figcaption id=\"caption-attachment-12107\" class=\"wp-caption-text\">Figure 1. Create a new Android application<\/figcaption><\/figure><\/p>\n<p>In the next window, the \u201cCreate Activity\u201d option should be checked. The new created activity will be the main activity of your project. Then press Next button.<\/p>\n<p><figure id=\"attachment_12108\" aria-describedby=\"caption-attachment-12108\" style=\"width: 504px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_proj2.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_proj2.png\" alt=\"Figure 2. Configure the project\" width=\"504\" height=\"472\" class=\"size-full wp-image-12108\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_proj2.png 504w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_proj2-300x280.png 300w\" sizes=\"(max-width: 504px) 100vw, 504px\" \/><\/a><figcaption id=\"caption-attachment-12108\" class=\"wp-caption-text\">Figure 2. Configure the project<\/figcaption><\/figure><\/p>\n<p>In \u201cConfigure Launcher Icon\u201d window you should choose the icon you want to have in your app. We will use the default icon of android, so click Next button.<\/p>\n<p><figure id=\"attachment_12109\" aria-describedby=\"caption-attachment-12109\" style=\"width: 628px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject3.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject3.png\" alt=\"Figure 3. Configure the launcher icon\" width=\"628\" height=\"495\" class=\"size-full wp-image-12109\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject3.png 628w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject3-300x236.png 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><figcaption id=\"caption-attachment-12109\" class=\"wp-caption-text\">Figure 3. Configure the launcher icon<\/figcaption><\/figure><\/p>\n<p>Select the \u201cBlank Activity\u201d option and press Next.<\/p>\n<p><figure id=\"attachment_12110\" aria-describedby=\"caption-attachment-12110\" style=\"width: 461px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject4.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject4.png\" alt=\"Figure 4. Create the activity and select its type\" width=\"461\" height=\"501\" class=\"size-full wp-image-12110\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject4.png 461w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject4-276x300.png 276w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><\/a><figcaption id=\"caption-attachment-12110\" class=\"wp-caption-text\">Figure 4. Create the activity and select its type<\/figcaption><\/figure><\/p>\n<p>You have to specify a name for the new Activity and a name for the layout description of your app. The .xml file for the layout will automatically be created in the&nbsp;<code>res\/layout<\/code>&nbsp;folder. Finally, press Finish.<\/p>\n<p><figure id=\"attachment_12111\" aria-describedby=\"caption-attachment-12111\" style=\"width: 457px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5.png\" alt=\"Figure 5. Create a new blank activity\" width=\"457\" height=\"469\" class=\"size-full wp-image-12111\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5.png 457w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5-292x300.png 292w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/AndroidCreateProject5-42x42.png 42w\" sizes=\"(max-width: 457px) 100vw, 457px\" \/><\/a><figcaption id=\"caption-attachment-12111\" class=\"wp-caption-text\">Figure 5. Create a new blank activity<\/figcaption><\/figure><\/p>\n<p>Now you can see the final structure of the project in the following image.<\/p>\n<p><figure id=\"attachment_12112\" aria-describedby=\"caption-attachment-12112\" style=\"width: 358px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_structureProj.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_structureProj.png\" alt=\"Figure 6. The final structure of the project\" width=\"358\" height=\"585\" class=\"size-full wp-image-12112\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_structureProj.png 358w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample_structureProj-183x300.png 183w\" sizes=\"(max-width: 358px) 100vw, 358px\" \/><\/a><figcaption id=\"caption-attachment-12112\" class=\"wp-caption-text\">Figure 6. The final structure of the project<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2><span id=\"code\">2. Create the layout of the Main Activity<\/span><\/h2>\n<p>Now we are going to create a simple UI that includes of course <code>RadioGroup<\/code>.<\/p>\n<p>Open <code>res\/layout\/activity_main.xml<\/code>, go to the respective tab and paste the following code.<\/p>\n<p><em><u>activity_main.xml:<\/u><\/em><\/p>\n<pre class=\"brush:xml\">&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\n    tools:context=\".MainActivity\" &gt;\n\n    &lt;TextView\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginBottom=\"10dp\"\n        android:id=\"@+id\/text\"\n        android:text=\"@string\/ChoiceText\" \/&gt;\n    \n    &lt;RadioGroup \n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_below=\"@+id\/text\"\n        android:id=\"@+id\/myRadioGroup\"\n        android:background=\"#abf234\"\n        android:checkedButton=\"@+id\/sound\" &gt;\n        \n        &lt;RadioButton \n            android:layout_width=\"wrap_content\"\n        \tandroid:layout_height=\"wrap_content\"\n        \tandroid:id=\"@+id\/sound\"\n        \tandroid:text=\"@string\/Sound\" \/&gt;\n        \n        &lt;RadioButton \n            android:layout_width=\"wrap_content\"\n        \tandroid:layout_height=\"wrap_content\"\n        \tandroid:id=\"@+id\/vibration\"\n        \tandroid:text=\"@string\/Vibration\" \/&gt;\n        \n        &lt;RadioButton \n            android:layout_width=\"wrap_content\"\n        \tandroid:layout_height=\"wrap_content\"\n        \tandroid:id=\"@+id\/silent\"\n        \tandroid:text=\"@string\/Silent\" \/&gt;\n        \n    &lt;\/RadioGroup&gt;\n    \n    &lt;Button \n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_below=\"@+id\/myRadioGroup\"\n        android:layout_marginTop=\"10dp\"\n        android:id=\"@+id\/chooseBtn\"\n        android:text=\"@string\/Choose\" \/&gt;\n\n&lt;\/RelativeLayout&gt;\n<\/pre>\n<p>The basic attribute of <code>RadioGroup<\/code> is <a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/RadioGroup.html#attr_android:checkedButton\" target=\"_blank\" rel=\"noopener noreferrer\"><code>android:checkedButton<\/code><\/a>, that specifies which radio button should be checked by default. The other components are inherited from the <code>View<\/code> class. As you can notice from the code above, the set of the radio buttons are embodied by a <code>RadioGroup<\/code>, so every configuration of its component affects the radio buttons too.<\/p>\n<h2>3. Set the string values<\/h2>\n<p>At this step we just going to declare the string references from the <code>activity_main.xml<\/code> to the appropriate resource.<\/p>\n<p>So open <code>res\/values\/strings.xml<\/code>, go to the respective tab and paste the following code.<\/p>\n<p><em><u>strings.xml<\/u><\/em><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;resources&gt;\n\n    &lt;string name=\"app_name\"&gt;RadioGroupExample&lt;\/string&gt;\n    &lt;string name=\"action_settings\"&gt;Settings&lt;\/string&gt;\n    &lt;string name=\"ChoiceText\"&gt;Choose one of the radio buttons below&lt;\/string&gt;\n    &lt;string name=\"Sound\"&gt;Sound&lt;\/string&gt;\n    &lt;string name=\"Vibration\"&gt;Vibration&lt;\/string&gt;\n    &lt;string name=\"Silent\"&gt;Silent&lt;\/string&gt;\n    &lt;string name=\"Choose\"&gt;Choose&lt;\/string&gt;\n\n&lt;\/resources&gt;\n<\/pre>\n<h2>4. Code the Main Activity<\/h2>\n<p>At this point we will show how we can handle the change of a radio button, that belongs to a <code>RadioGroup<\/code>.<\/p>\n<p>Open <code>src\/com.javacodegeeks.android.radiogroupexample\/MainActivity.java<\/code>&nbsp;and paste the following code.<\/p>\n<p><em><u>MainActivity.java:<\/u><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.android.radiogroupexample;\n\nimport android.os.Bundle;\nimport android.app.Activity;\nimport android.view.View;\nimport android.view.View.OnClickListener;\nimport android.widget.Button;\nimport android.widget.RadioButton;\nimport android.widget.RadioGroup;\nimport android.widget.RadioGroup.OnCheckedChangeListener;\nimport android.widget.TextView;\nimport android.widget.Toast;\n\npublic class MainActivity extends Activity {\n\t\n\tprivate RadioGroup radioGroup;\n\tprivate RadioButton sound, vibration, silent; \n\tprivate Button button;\n\tprivate TextView textView;\n\n\t@Override\n\tprotected void onCreate(Bundle savedInstanceState) {\n\t\tsuper.onCreate(savedInstanceState);\n\t\tsetContentView(R.layout.activity_main);\n\t\t\n\t\tradioGroup = (RadioGroup) findViewById(R.id.myRadioGroup);\n\t\t\n\t\tradioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {\n\n\t\t\t@Override\n\t\t\tpublic void onCheckedChanged(RadioGroup group, int checkedId) {\n\t\t\t\t\/\/ find which radio button is selected\n\t\t\t\tif(checkedId == R.id.silent) {\n\t\t\t\t\tToast.makeText(getApplicationContext(), \"choice: Silent\", \n\t\t\t\t\t\t\tToast.LENGTH_SHORT).show();\n\t\t\t\t} else if(checkedId == R.id.sound) {\n\t\t\t\t\tToast.makeText(getApplicationContext(), \"choice: Sound\", \n\t\t\t\t\t\t\tToast.LENGTH_SHORT).show();\n\t\t\t\t} else {\n\t\t\t\t\tToast.makeText(getApplicationContext(), \"choice: Vibration\", \n\t\t\t\t\t\t\tToast.LENGTH_SHORT).show();\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t});\n\t\t\n\t\tsound = (RadioButton) findViewById(R.id.sound);\n\t\tvibration = (RadioButton) findViewById(R.id.vibration);\n\t    silent = (RadioButton) findViewById(R.id.silent);\n\t    textView = (TextView) findViewById(R.id.text);\n\t    \n\t    button = (Button)findViewById(R.id.chooseBtn);\n\t    button.setOnClickListener(new OnClickListener() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic void onClick(View v) {\n\t\t\t\tint selectedId = radioGroup.getCheckedRadioButtonId();\n\t\t\t\t\n\t\t\t\t\/\/ find which radioButton is checked by id\n\t\t\t\tif(selectedId == sound.getId()) {\n\t\t\t\t\ttextView.setText(\"You chose 'Sound' option\");\n\t\t\t\t} else if(selectedId == vibration.getId()) {\n\t\t\t\t\ttextView.setText(\"You chose 'Vibration' option\");\n\t\t\t\t} else {\n\t\t\t\t\ttextView.setText(\"You chose 'Silent' option\");\n\t\t\t\t}\t\n\t\t\t}\n\t    });\n\t}\n\n}\n<\/pre>\n<p>Now let&#8217;s have a look at the code above. When a checked radio button is changed in its group, <a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/RadioGroup.OnCheckedChangeListener.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>OnCheckedChangeListener<\/code><\/a> is invoked in order to handle this situation. The <code>onCheckedChanged()<\/code> method of this interface, includes the unique id of the radio button that was selected and caused the invoke of the callback.[ulp id=&#8217;Ja8Orb5oPKdShcXt&#8217;]<\/p>\n<p>In this example we will show you another way of selecting the choice information (for example when a button is pressed).  This can be done through <a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/RadioGroup.html#getCheckedRadioButtonId()\" target=\"_blank\" rel=\"noopener noreferrer\"><code>getCheckedRadioButtonId()<\/code><\/a>, which is a public function of <code>RadioGroup<\/code> class. This method returns the unique id of the radio button that is chosen from the group. You can have a look at the code to see how you can handle both situations.<\/p>\n<p>Of course Android system provides us a more dynamic way of changing and handling the attributes of the application views. As a prerequisite is to map every view with the unique id component of the XML. This can be done via <code>findViewById()<\/code> method.<\/p>\n<h2>5. Run the application<\/h2>\n<p>To run our application, right click on our project \u2192 Run as \u2192 Android Application. The AVD will appear with the app loaded.<\/p>\n<p><figure id=\"attachment_12113\" aria-describedby=\"caption-attachment-12113\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD1.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD1.png\" alt=\"Figure 7: The Android app is loaded\" width=\"256\" height=\"359\" class=\"size-full wp-image-12113\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD1.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD1-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-12113\" class=\"wp-caption-text\">Figure 7: The Android app is loaded<\/figcaption><\/figure><\/p>\n<p>As you can see, the radio button \u2013 &#8220;Sound&#8221; is selected as default because we declared it through its id to the <code>android:checkedButton<\/code> attribute at the layout of the activity.<\/p>\n<p>Now let&#8217;s choose another radio button, for example &#8220;Vibration&#8221;. A <code>Toast<\/code> is displayed on the screen because the callback method of the <code>OnCheckedChangeListener<\/code> is initialized.<\/p>\n<p><figure id=\"attachment_12114\" aria-describedby=\"caption-attachment-12114\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD2.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD2.png\" alt=\"Figure 8: Selection of another radio button\" width=\"256\" height=\"359\" class=\"size-full wp-image-12114\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD2.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD2-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-12114\" class=\"wp-caption-text\">Figure 8: Selection of another radio button<\/figcaption><\/figure><\/p>\n<p>Now let&#8217;s select &#8220;Silent&#8221; radio button and after the disappearance of the <code>Toast<\/code> press &#8220;Choose&#8221; button. The <code>TextView<\/code> at the top of the screen changes to indicate our choice, as you can see in the next image. This is happening because  <code>getCheckedRadioButtonId()<\/code>  is called  and a simple procedure is done inside the <code>onClick()<\/code> operation of the <code>OnClickListener<\/code> interface, as you can see in the <code>MainActivity.java<\/code>.<\/p>\n<p><figure id=\"attachment_12115\" aria-describedby=\"caption-attachment-12115\" style=\"width: 256px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD3.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD3.png\" alt=\"Figure 9: Press the &quot;Choose&quot; button after selecting another radio button\" width=\"256\" height=\"359\" class=\"size-full wp-image-12115\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD3.png 256w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExampleAVD3-213x300.png 213w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption id=\"caption-attachment-12115\" class=\"wp-caption-text\">Figure 9: Press the &#8220;Choose&#8221; button after selecting another radio button<\/figcaption><\/figure><\/p>\n<h2>Download the Eclipse Project<\/h2>\n<p>This was an example of RadioGroup in Android.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here : <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/RadioGroupExample.zip\"><strong>RadioGroupExample.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>RadioGroup is a widget in Android which groups RadioButtons. More specifically, the use of RadioGroup provides the capability of selecting only one RadioButton from the set. When the user chooses one RadioButton, the previous one that was selected, becomes automatically unchecked. In our example we are going to show you the use of RadioGroup in &hellip;<\/p>\n","protected":false},"author":11,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[330],"tags":[629,1120],"class_list":["post-12105","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-radiogroup","tag-oncheckedchangelistener","tag-radiobutton"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android RadioGroup Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"RadioGroup is a widget in Android which groups RadioButtons. More specifically, the use of RadioGroup provides the capability of selecting only one\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android RadioGroup Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"RadioGroup is a widget in Android which groups RadioButtons. More specifically, the use of RadioGroup provides the capability of selecting only one\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-23T13:12:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-24T13:06:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Katerina Zamani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Katerina Zamani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/\"},\"author\":{\"name\":\"Katerina Zamani\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673\"},\"headline\":\"Android RadioGroup Example\",\"datePublished\":\"2014-07-23T13:12:31+00:00\",\"dateModified\":\"2019-04-24T13:06:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/\"},\"wordCount\":843,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"keywords\":[\"OnCheckedChangeListener\",\"RadioButton\"],\"articleSection\":[\"RadioGroup\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/\",\"name\":\"Android RadioGroup Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2014-07-23T13:12:31+00:00\",\"dateModified\":\"2019-04-24T13:06:23+00:00\",\"description\":\"RadioGroup is a widget in Android which groups RadioButtons. More specifically, the use of RadioGroup provides the capability of selecting only one\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"core\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"ui\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/ui\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"RadioGroup\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/ui\/radiogroup\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Android RadioGroup Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673\",\"name\":\"Katerina Zamani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg\",\"caption\":\"Katerina Zamani\"},\"description\":\"Katerina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she attends MSc courses in Advanced Information Systems at the same department. Currently, her main academic interests focus on web applications, mobile development, software engineering, databases and telecommunications.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/katerina-zamani\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android RadioGroup Example - Java Code Geeks","description":"RadioGroup is a widget in Android which groups RadioButtons. More specifically, the use of RadioGroup provides the capability of selecting only one","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:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/","og_locale":"en_US","og_type":"article","og_title":"Android RadioGroup Example - Java Code Geeks","og_description":"RadioGroup is a widget in Android which groups RadioButtons. More specifically, the use of RadioGroup provides the capability of selecting only one","og_url":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-07-23T13:12:31+00:00","article_modified_time":"2019-04-24T13:06:23+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","type":"image\/jpeg"}],"author":"Katerina Zamani","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Katerina Zamani","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/"},"author":{"name":"Katerina Zamani","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673"},"headline":"Android RadioGroup Example","datePublished":"2014-07-23T13:12:31+00:00","dateModified":"2019-04-24T13:06:23+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/"},"wordCount":843,"commentCount":2,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","keywords":["OnCheckedChangeListener","RadioButton"],"articleSection":["RadioGroup"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/","url":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/","name":"Android RadioGroup Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2014-07-23T13:12:31+00:00","dateModified":"2019-04-24T13:06:23+00:00","description":"RadioGroup is a widget in Android which groups RadioButtons. More specifically, the use of RadioGroup provides the capability of selecting only one","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/ui\/radiogroup\/android-radiogroup-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/"},{"@type":"ListItem","position":3,"name":"core","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/"},{"@type":"ListItem","position":4,"name":"ui","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/ui\/"},{"@type":"ListItem","position":5,"name":"RadioGroup","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/ui\/radiogroup\/"},{"@type":"ListItem","position":6,"name":"Android RadioGroup Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/94be714b6b9a82bb855c0d370c319673","name":"Katerina Zamani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/Katerina-Zamani-96x96.jpg","caption":"Katerina Zamani"},"description":"Katerina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she attends MSc courses in Advanced Information Systems at the same department. Currently, her main academic interests focus on web applications, mobile development, software engineering, databases and telecommunications.","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/katerina-zamani\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=12105"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12105\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1202"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=12105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=12105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=12105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}